home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / gcc_260.zip / gcc_260 / function.c < prev    next >
C/C++ Source or Header  |  1994-07-13  |  173KB  |  5,497 lines

  1. /* Expands front end tree to back end RTL for GNU C-Compiler
  2.    Copyright (C) 1987, 88, 89, 91, 92, 93, 1994 Free Software Foundation, Inc.
  3.  
  4. This file is part of GNU CC.
  5.  
  6. GNU CC is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2, or (at your option)
  9. any later version.
  10.  
  11. GNU CC is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GNU CC; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20.  
  21. /* This file handles the generation of rtl code from tree structure
  22.    at the level of the function as a whole.
  23.    It creates the rtl expressions for parameters and auto variables
  24.    and has full responsibility for allocating stack slots.
  25.  
  26.    `expand_function_start' is called at the beginning of a function,
  27.    before the function body is parsed, and `expand_function_end' is
  28.    called after parsing the body.
  29.  
  30.    Call `assign_stack_local' to allocate a stack slot for a local variable.
  31.    This is usually done during the RTL generation for the function body,
  32.    but it can also be done in the reload pass when a pseudo-register does
  33.    not get a hard register.
  34.  
  35.    Call `put_var_into_stack' when you learn, belatedly, that a variable
  36.    previously given a pseudo-register must in fact go in the stack.
  37.    This function changes the DECL_RTL to be a stack slot instead of a reg
  38.    then scans all the RTL instructions so far generated to correct them.  */
  39.  
  40. #include "config.h"
  41.  
  42. #include <stdio.h>
  43.  
  44. #include "rtl.h"
  45. #include "tree.h"
  46. #include "flags.h"
  47. #include "function.h"
  48. #include "insn-flags.h"
  49. #include "expr.h"
  50. #include "insn-codes.h"
  51. #include "regs.h"
  52. #include "hard-reg-set.h"
  53. #include "insn-config.h"
  54. #include "recog.h"
  55. #include "output.h"
  56. #include "basic-block.h"
  57. #include "obstack.h"
  58. #include "bytecode.h"
  59.  
  60. /* Some systems use __main in a way incompatible with its use in gcc, in these
  61.    cases use the macros NAME__MAIN to give a quoted symbol and SYMBOL__MAIN to
  62.    give the same symbol without quotes for an alternative entry point.  You
  63.    must define both, or niether. */
  64. #ifndef NAME__MAIN
  65. #define NAME__MAIN "__main"
  66. #define SYMBOL__MAIN __main
  67. #endif
  68.  
  69. /* Round a value to the lowest integer less than it that is a multiple of
  70.    the required alignment.  Avoid using division in case the value is
  71.    negative.  Assume the alignment is a power of two.  */
  72. #define FLOOR_ROUND(VALUE,ALIGN) ((VALUE) & ~((ALIGN) - 1))
  73.  
  74. /* Similar, but round to the next highest integer that meets the
  75.    alignment.  */
  76. #define CEIL_ROUND(VALUE,ALIGN)    (((VALUE) + (ALIGN) - 1) & ~((ALIGN)- 1))
  77.  
  78. /* NEED_SEPARATE_AP means that we cannot derive ap from the value of fp
  79.    during rtl generation.  If they are different register numbers, this is
  80.    always true.  It may also be true if
  81.    FIRST_PARM_OFFSET - STARTING_FRAME_OFFSET is not a constant during rtl
  82.    generation.  See fix_lexical_addr for details.  */
  83.  
  84. #if ARG_POINTER_REGNUM != FRAME_POINTER_REGNUM
  85. #define NEED_SEPARATE_AP
  86. #endif
  87.  
  88. /* Number of bytes of args popped by function being compiled on its return.
  89.    Zero if no bytes are to be popped.
  90.    May affect compilation of return insn or of function epilogue.  */
  91.  
  92. int current_function_pops_args;
  93.  
  94. /* Nonzero if function being compiled needs to be given an address
  95.    where the value should be stored.  */
  96.  
  97. int current_function_returns_struct;
  98.  
  99. /* Nonzero if function being compiled needs to
  100.    return the address of where it has put a structure value.  */
  101.  
  102. int current_function_returns_pcc_struct;
  103.  
  104. /* Nonzero if function being compiled needs to be passed a static chain.  */
  105.  
  106. int current_function_needs_context;
  107.  
  108. /* Nonzero if function being compiled can call setjmp.  */
  109.  
  110. int current_function_calls_setjmp;
  111.  
  112. /* Nonzero if function being compiled can call longjmp.  */
  113.  
  114. int current_function_calls_longjmp;
  115.  
  116. /* Nonzero if function being compiled receives nonlocal gotos
  117.    from nested functions.  */
  118.  
  119. int current_function_has_nonlocal_label;
  120.  
  121. /* Nonzero if function being compiled has nonlocal gotos to parent
  122.    function.  */
  123.  
  124. int current_function_has_nonlocal_goto;
  125.  
  126. /* Nonzero if function being compiled contains nested functions.  */
  127.  
  128. int current_function_contains_functions;
  129.  
  130. /* Nonzero if function being compiled can call alloca,
  131.    either as a subroutine or builtin.  */
  132.  
  133. int current_function_calls_alloca;
  134.  
  135. /* Nonzero if the current function returns a pointer type */
  136.  
  137. int current_function_returns_pointer;
  138.  
  139. /* If some insns can be deferred to the delay slots of the epilogue, the
  140.    delay list for them is recorded here.  */
  141.  
  142. rtx current_function_epilogue_delay_list;
  143.  
  144. /* If function's args have a fixed size, this is that size, in bytes.
  145.    Otherwise, it is -1.
  146.    May affect compilation of return insn or of function epilogue.  */
  147.  
  148. int current_function_args_size;
  149.  
  150. /* # bytes the prologue should push and pretend that the caller pushed them.
  151.    The prologue must do this, but only if parms can be passed in registers.  */
  152.  
  153. int current_function_pretend_args_size;
  154.  
  155. /* # of bytes of outgoing arguments required to be pushed by the prologue.
  156.    If this is non-zero, it means that ACCUMULATE_OUTGOING_ARGS was defined
  157.    and no stack adjusts will be done on function calls.  */
  158.  
  159. int current_function_outgoing_args_size;
  160.  
  161. /* This is the offset from the arg pointer to the place where the first
  162.    anonymous arg can be found, if there is one.  */
  163.  
  164. rtx current_function_arg_offset_rtx;
  165.  
  166. /* Nonzero if current function uses varargs.h or equivalent.
  167.    Zero for functions that use stdarg.h.  */
  168.  
  169. int current_function_varargs;
  170.  
  171. /* Quantities of various kinds of registers
  172.    used for the current function's args.  */
  173.  
  174. CUMULATIVE_ARGS current_function_args_info;
  175.  
  176. /* Name of function now being compiled.  */
  177.  
  178. char *current_function_name;
  179.  
  180. /* If non-zero, an RTL expression for that location at which the current
  181.    function returns its result.  Always equal to
  182.    DECL_RTL (DECL_RESULT (current_function_decl)), but provided
  183.    independently of the tree structures.  */
  184.  
  185. rtx current_function_return_rtx;
  186.  
  187. /* Nonzero if the current function uses the constant pool.  */
  188.  
  189. int current_function_uses_const_pool;
  190.  
  191. /* Nonzero if the current function uses pic_offset_table_rtx.  */
  192. int current_function_uses_pic_offset_table;
  193.  
  194. /* The arg pointer hard register, or the pseudo into which it was copied.  */
  195. rtx current_function_internal_arg_pointer;
  196.  
  197. /* The FUNCTION_DECL for an inline function currently being expanded.  */
  198. tree inline_function_decl;
  199.  
  200. /* Number of function calls seen so far in current function.  */
  201.  
  202. int function_call_count;
  203.  
  204. /* List (chain of TREE_LIST) of LABEL_DECLs for all nonlocal labels
  205.    (labels to which there can be nonlocal gotos from nested functions)
  206.    in this function.  */
  207.  
  208. tree nonlocal_labels;
  209.  
  210. /* RTX for stack slot that holds the current handler for nonlocal gotos.
  211.    Zero when function does not have nonlocal labels.  */
  212.  
  213. rtx nonlocal_goto_handler_slot;
  214.  
  215. /* RTX for stack slot that holds the stack pointer value to restore
  216.    for a nonlocal goto.
  217.    Zero when function does not have nonlocal labels.  */
  218.  
  219. rtx nonlocal_goto_stack_level;
  220.  
  221. /* Label that will go on parm cleanup code, if any.
  222.    Jumping to this label runs cleanup code for parameters, if
  223.    such code must be run.  Following this code is the logical return label.  */
  224.  
  225. rtx cleanup_label;
  226.  
  227. /* Label that will go on function epilogue.
  228.    Jumping to this label serves as a "return" instruction
  229.    on machines which require execution of the epilogue on all returns.  */
  230.  
  231. rtx return_label;
  232.  
  233. /* List (chain of EXPR_LISTs) of pseudo-regs of SAVE_EXPRs.
  234.    So we can mark them all live at the end of the function, if nonopt.  */
  235. rtx save_expr_regs;
  236.  
  237. /* List (chain of EXPR_LISTs) of all stack slots in this function.
  238.    Made for the sake of unshare_all_rtl.  */
  239. rtx stack_slot_list;
  240.  
  241. /* Chain of all RTL_EXPRs that have insns in them.  */
  242. tree rtl_expr_chain;
  243.  
  244. /* Label to jump back to for tail recursion, or 0 if we have
  245.    not yet needed one for this function.  */
  246. rtx tail_recursion_label;
  247.  
  248. /* Place after which to insert the tail_recursion_label if we need one.  */
  249. rtx tail_recursion_reentry;
  250.  
  251. /* Location at which to save the argument pointer if it will need to be
  252.    referenced.  There are two cases where this is done: if nonlocal gotos
  253.    exist, or if vars stored at an offset from the argument pointer will be
  254.    needed by inner routines.  */
  255.  
  256. rtx arg_pointer_save_area;
  257.  
  258. /* Offset to end of allocated area of stack frame.
  259.    If stack grows down, this is the address of the last stack slot allocated.
  260.    If stack grows up, this is the address for the next slot.  */
  261. int frame_offset;
  262.  
  263. /* List (chain of TREE_LISTs) of static chains for containing functions.
  264.    Each link has a FUNCTION_DECL in the TREE_PURPOSE and a reg rtx
  265.    in an RTL_EXPR in the TREE_VALUE.  */
  266. static tree context_display;
  267.  
  268. /* List (chain of TREE_LISTs) of trampolines for nested functions.
  269.    The trampoline sets up the static chain and jumps to the function.
  270.    We supply the trampoline's address when the function's address is requested.
  271.  
  272.    Each link has a FUNCTION_DECL in the TREE_PURPOSE and a reg rtx
  273.    in an RTL_EXPR in the TREE_VALUE.  */
  274. static tree trampoline_list;
  275.  
  276. /* Insn after which register parms and SAVE_EXPRs are born, if nonopt.  */
  277. static rtx parm_birth_insn;
  278.  
  279. #if 0
  280. /* Nonzero if a stack slot has been generated whose address is not
  281.    actually valid.  It means that the generated rtl must all be scanned
  282.    to detect and correct the invalid addresses where they occur.  */
  283. static int invalid_stack_slot;
  284. #endif
  285.  
  286. /* Last insn of those whose job was to put parms into their nominal homes.  */
  287. static rtx last_parm_insn;
  288.  
  289. /* 1 + last pseudo register number used for loading a copy
  290.    of a parameter of this function.  */
  291. static int max_parm_reg;
  292.  
  293. /* Vector indexed by REGNO, containing location on stack in which
  294.    to put the parm which is nominally in pseudo register REGNO,
  295.    if we discover that that parm must go in the stack.  */
  296. static rtx *parm_reg_stack_loc;
  297.  
  298. #if 0  /* Turned off because 0 seems to work just as well.  */
  299. /* Cleanup lists are required for binding levels regardless of whether
  300.    that binding level has cleanups or not.  This node serves as the
  301.    cleanup list whenever an empty list is required.  */
  302. static tree empty_cleanup_list;
  303. #endif
  304.  
  305. /* Nonzero once virtual register instantiation has been done.
  306.    assign_stack_local uses frame_pointer_rtx when this is nonzero.  */
  307. static int virtuals_instantiated;
  308.  
  309. /* These variables hold pointers to functions to
  310.    save and restore machine-specific data,
  311.    in push_function_context and pop_function_context.  */
  312. void (*save_machine_status) ();
  313. void (*restore_machine_status) ();
  314.  
  315. /* Nonzero if we need to distinguish between the return value of this function
  316.    and the return value of a function called by this function.  This helps
  317.    integrate.c  */
  318.  
  319. extern int rtx_equal_function_value_matters;
  320. extern tree sequence_rtl_expr;
  321. extern tree bc_runtime_type_code ();
  322. extern rtx bc_build_calldesc ();
  323. extern char *bc_emit_trampoline ();
  324. extern char *bc_end_function ();
  325.  
  326. /* In order to evaluate some expressions, such as function calls returning
  327.    structures in memory, we need to temporarily allocate stack locations.
  328.    We record each allocated temporary in the following structure.
  329.  
  330.    Associated with each temporary slot is a nesting level.  When we pop up
  331.    one level, all temporaries associated with the previous level are freed.
  332.    Normally, all temporaries are freed after the execution of the statement
  333.    in which they were created.  However, if we are inside a ({...}) grouping,
  334.    the result may be in a temporary and hence must be preserved.  If the
  335.    result could be in a temporary, we preserve it if we can determine which
  336.    one it is in.  If we cannot determine which temporary may contain the
  337.    result, all temporaries are preserved.  A temporary is preserved by
  338.    pretending it was allocated at the previous nesting level.
  339.  
  340.    Automatic variables are also assigned temporary slots, at the nesting
  341.    level where they are defined.  They are marked a "kept" so that
  342.    free_temp_slots will not free them.  */
  343.  
  344. struct temp_slot
  345. {
  346.   /* Points to next temporary slot.  */
  347.   struct temp_slot *next;
  348.   /* The rtx to used to reference the slot. */
  349.   rtx slot;
  350.   /* The rtx used to represent the address if not the address of the
  351.      slot above.  May be an EXPR_LIST if multiple addresses exist.  */
  352.   rtx address;
  353.   /* The size, in units, of the slot.  */
  354.   int size;
  355.   /* The value of `sequence_rtl_expr' when this temporary is allocated.  */
  356.   tree rtl_expr;
  357.   /* Non-zero if this temporary is currently in use.  */
  358.   char in_use;
  359.   /* Nesting level at which this slot is being used.  */
  360.   int level;
  361.   /* Non-zero if this should survive a call to free_temp_slots.  */
  362.   int keep;
  363. };
  364.  
  365. /* List of all temporaries allocated, both available and in use.  */
  366.  
  367. struct temp_slot *temp_slots;
  368.  
  369. /* Current nesting level for temporaries.  */
  370.  
  371. int temp_slot_level;
  372.  
  373. /* The FUNCTION_DECL node for the current function.  */
  374. static tree this_function_decl;
  375.  
  376. /* Callinfo pointer for the current function.  */
  377. static rtx this_function_callinfo;
  378.  
  379. /* The label in the bytecode file of this function's actual bytecode.
  380.    Not an rtx.  */
  381. static char *this_function_bytecode;
  382.  
  383. /* The call description vector for the current function.  */
  384. static rtx this_function_calldesc;
  385.  
  386. /* Size of the local variables allocated for the current function.  */
  387. int local_vars_size;
  388.  
  389. /* Current depth of the bytecode evaluation stack.  */
  390. int stack_depth;
  391.  
  392. /* Maximum depth of the evaluation stack in this function.  */
  393. int max_stack_depth;
  394.  
  395. /* Current depth in statement expressions.  */
  396. static int stmt_expr_depth;
  397.  
  398. /* This structure is used to record MEMs or pseudos used to replace VAR, any
  399.    SUBREGs of VAR, and any MEMs containing VAR as an address.  We need to
  400.    maintain this list in case two operands of an insn were required to match;
  401.    in that case we must ensure we use the same replacement.  */
  402.  
  403. struct fixup_replacement
  404. {
  405.   rtx old;
  406.   rtx new;
  407.   struct fixup_replacement *next;
  408. };
  409.    
  410. /* Forward declarations.  */
  411.  
  412. static struct temp_slot *find_temp_slot_from_address  PROTO((rtx));
  413. static void put_reg_into_stack    PROTO((struct function *, rtx, tree,
  414.                        enum machine_mode, enum machine_mode));
  415. static void fixup_var_refs    PROTO((rtx, enum machine_mode, int));
  416. static struct fixup_replacement
  417.   *find_fixup_replacement    PROTO((struct fixup_replacement **, rtx));
  418. static void fixup_var_refs_insns PROTO((rtx, enum machine_mode, int,
  419.                     rtx, int));
  420. static void fixup_var_refs_1    PROTO((rtx, enum machine_mode, rtx *, rtx,
  421.                        struct fixup_replacement **));
  422. static rtx fixup_memory_subreg    PROTO((rtx, rtx, int));
  423. static rtx walk_fixup_memory_subreg  PROTO((rtx, rtx, int));
  424. static rtx fixup_stack_1    PROTO((rtx, rtx));
  425. static void optimize_bit_field    PROTO((rtx, rtx, rtx *));
  426. static void instantiate_decls    PROTO((tree, int));
  427. static void instantiate_decls_1    PROTO((tree, int));
  428. static void instantiate_decl    PROTO((rtx, int, int));
  429. static int instantiate_virtual_regs_1 PROTO((rtx *, rtx, int));
  430. static void delete_handlers    PROTO((void));
  431. static void pad_to_arg_alignment PROTO((struct args_size *, int));
  432. static void pad_below        PROTO((struct args_size *, enum  machine_mode,
  433.                        tree));
  434. static tree round_down        PROTO((tree, int));
  435. static rtx round_trampoline_addr PROTO((rtx));
  436. static tree blocks_nreverse    PROTO((tree));
  437. static int all_blocks        PROTO((tree, tree *));
  438. static int *record_insns    PROTO((rtx));
  439. static int contains        PROTO((rtx, int *));
  440.  
  441. /* Pointer to chain of `struct function' for containing functions.  */
  442. struct function *outer_function_chain;
  443.  
  444. /* Given a function decl for a containing function,
  445.    return the `struct function' for it.  */
  446.  
  447. struct function *
  448. find_function_data (decl)
  449.      tree decl;
  450. {
  451.   struct function *p;
  452.   for (p = outer_function_chain; p; p = p->next)
  453.     if (p->decl == decl)
  454.       return p;
  455.   abort ();
  456. }
  457.  
  458. /* Save the current context for compilation of a nested function.
  459.    This is called from language-specific code.
  460.    The caller is responsible for saving any language-specific status,
  461.    since this function knows only about language-independent variables.  */
  462.  
  463. void
  464. push_function_context ()
  465. {
  466.   struct function *p = (struct function *) xmalloc (sizeof (struct function));
  467.  
  468.   p->next = outer_function_chain;
  469.   outer_function_chain = p;
  470.  
  471.   p->name = current_function_name;
  472.   p->decl = current_function_decl;
  473.   p->pops_args = current_function_pops_args;
  474.   p->returns_struct = current_function_returns_struct;
  475.   p->returns_pcc_struct = current_function_returns_pcc_struct;
  476.   p->needs_context = current_function_needs_context;
  477.   p->calls_setjmp = current_function_calls_setjmp;
  478.   p->calls_longjmp = current_function_calls_longjmp;
  479.   p->calls_alloca = current_function_calls_alloca;
  480.   p->has_nonlocal_label = current_function_has_nonlocal_label;
  481.   p->has_nonlocal_goto = current_function_has_nonlocal_goto;
  482.   p->args_size = current_function_args_size;
  483.   p->pretend_args_size = current_function_pretend_args_size;
  484.   p->arg_offset_rtx = current_function_arg_offset_rtx;
  485.   p->varargs = current_function_varargs;
  486.   p->uses_const_pool = current_function_uses_const_pool;
  487.   p->uses_pic_offset_table = current_function_uses_pic_offset_table;
  488.   p->internal_arg_pointer = current_function_internal_arg_pointer;
  489.   p->max_parm_reg = max_parm_reg;
  490.   p->parm_reg_stack_loc = parm_reg_stack_loc;
  491.   p->outgoing_args_size = current_function_outgoing_args_size;
  492.   p->return_rtx = current_function_return_rtx;
  493.   p->nonlocal_goto_handler_slot = nonlocal_goto_handler_slot;
  494.   p->nonlocal_goto_stack_level = nonlocal_goto_stack_level;
  495.   p->nonlocal_labels = nonlocal_labels;
  496.   p->cleanup_label = cleanup_label;
  497.   p->return_label = return_label;
  498.   p->save_expr_regs = save_expr_regs;
  499.   p->stack_slot_list = stack_slot_list;
  500.   p->parm_birth_insn = parm_birth_insn;
  501.   p->frame_offset = frame_offset;
  502.   p->tail_recursion_label = tail_recursion_label;
  503.   p->tail_recursion_reentry = tail_recursion_reentry;
  504.   p->arg_pointer_save_area = arg_pointer_save_area;
  505.   p->rtl_expr_chain = rtl_expr_chain;
  506.   p->last_parm_insn = last_parm_insn;
  507.   p->context_display = context_display;
  508.   p->trampoline_list = trampoline_list;
  509.   p->function_call_count = function_call_count;
  510.   p->temp_slots = temp_slots;
  511.   p->temp_slot_level = temp_slot_level;
  512.   p->fixup_var_refs_queue = 0;
  513.   p->epilogue_delay_list = current_function_epilogue_delay_list;
  514.  
  515.   save_tree_status (p);
  516.   save_storage_status (p);
  517.   save_emit_status (p);
  518.   init_emit ();
  519.   save_expr_status (p);
  520.   save_stmt_status (p);
  521.   save_varasm_status (p);
  522.  
  523.   if (save_machine_status)
  524.     (*save_machine_status) (p);
  525. }
  526.  
  527. /* Restore the last saved context, at the end of a nested function.
  528.    This function is called from language-specific code.  */
  529.  
  530. void
  531. pop_function_context ()
  532. {
  533.   struct function *p = outer_function_chain;
  534.  
  535.   outer_function_chain = p->next;
  536.  
  537.   current_function_name = p->name;
  538.   current_function_decl = p->decl;
  539.   current_function_pops_args = p->pops_args;
  540.   current_function_returns_struct = p->returns_struct;
  541.   current_function_returns_pcc_struct = p->returns_pcc_struct;
  542.   current_function_needs_context = p->needs_context;
  543.   current_function_calls_setjmp = p->calls_setjmp;
  544.   current_function_calls_longjmp = p->calls_longjmp;
  545.   current_function_calls_alloca = p->calls_alloca;
  546.   current_function_has_nonlocal_label = p->has_nonlocal_label;
  547.   current_function_has_nonlocal_goto = p->has_nonlocal_goto;
  548.   current_function_contains_functions = 1;
  549.   current_function_args_size = p->args_size;
  550.   current_function_pretend_args_size = p->pretend_args_size;
  551.   current_function_arg_offset_rtx = p->arg_offset_rtx;
  552.   current_function_varargs = p->varargs;
  553.   current_function_uses_const_pool = p->uses_const_pool;
  554.   current_function_uses_pic_offset_table = p->uses_pic_offset_table;
  555.   current_function_internal_arg_pointer = p->internal_arg_pointer;
  556.   max_parm_reg = p->max_parm_reg;
  557.   parm_reg_stack_loc = p->parm_reg_stack_loc;
  558.   current_function_outgoing_args_size = p->outgoing_args_size;
  559.   current_function_return_rtx = p->return_rtx;
  560.   nonlocal_goto_handler_slot = p->nonlocal_goto_handler_slot;
  561.   nonlocal_goto_stack_level = p->nonlocal_goto_stack_level;
  562.   nonlocal_labels = p->nonlocal_labels;
  563.   cleanup_label = p->cleanup_label;
  564.   return_label = p->return_label;
  565.   save_expr_regs = p->save_expr_regs;
  566.   stack_slot_list = p->stack_slot_list;
  567.   parm_birth_insn = p->parm_birth_insn;
  568.   frame_offset = p->frame_offset;
  569.   tail_recursion_label = p->tail_recursion_label;
  570.   tail_recursion_reentry = p->tail_recursion_reentry;
  571.   arg_pointer_save_area = p->arg_pointer_save_area;
  572.   rtl_expr_chain = p->rtl_expr_chain;
  573.   last_parm_insn = p->last_parm_insn;
  574.   context_display = p->context_display;
  575.   trampoline_list = p->trampoline_list;
  576.   function_call_count = p->function_call_count;
  577.   temp_slots = p->temp_slots;
  578.   temp_slot_level = p->temp_slot_level;
  579.   current_function_epilogue_delay_list = p->epilogue_delay_list;
  580.  
  581.   restore_tree_status (p);
  582.   restore_storage_status (p);
  583.   restore_expr_status (p);
  584.   restore_emit_status (p);
  585.   restore_stmt_status (p);
  586.   restore_varasm_status (p);
  587.  
  588.   if (restore_machine_status)
  589.     (*restore_machine_status) (p);
  590.  
  591.   /* Finish doing put_var_into_stack for any of our variables
  592.      which became addressable during the nested function.  */
  593.   {
  594.     struct var_refs_queue *queue = p->fixup_var_refs_queue;
  595.     for (; queue; queue = queue->next)
  596.       fixup_var_refs (queue->modified, queue->promoted_mode, queue->unsignedp);
  597.   }
  598.  
  599.   free (p);
  600.  
  601.   /* Reset variables that have known state during rtx generation.  */
  602.   rtx_equal_function_value_matters = 1;
  603.   virtuals_instantiated = 0;
  604. }
  605.  
  606. /* Allocate fixed slots in the stack frame of the current function.  */
  607.  
  608. /* Return size needed for stack frame based on slots so far allocated.
  609.    This size counts from zero.  It is not rounded to STACK_BOUNDARY;
  610.    the caller may have to do that.  */
  611.  
  612. int
  613. get_frame_size ()
  614. {
  615. #ifdef FRAME_GROWS_DOWNWARD
  616.   return -frame_offset;
  617. #else
  618.   return frame_offset;
  619. #endif
  620. }
  621.  
  622. /* Allocate a stack slot of SIZE bytes and return a MEM rtx for it
  623.    with machine mode MODE.
  624.    
  625.    ALIGN controls the amount of alignment for the address of the slot:
  626.    0 means according to MODE,
  627.    -1 means use BIGGEST_ALIGNMENT and round size to multiple of that,
  628.    positive specifies alignment boundary in bits.
  629.  
  630.    We do not round to stack_boundary here.  */
  631.  
  632. rtx
  633. assign_stack_local (mode, size, align)
  634.      enum machine_mode mode;
  635.      int size;
  636.      int align;
  637. {
  638.   register rtx x, addr;
  639.   int bigend_correction = 0;
  640.   int alignment;
  641.  
  642.   if (align == 0)
  643.     {
  644.       alignment = GET_MODE_ALIGNMENT (mode) / BITS_PER_UNIT;
  645.       if (mode == BLKmode)
  646.     alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
  647.     }
  648.   else if (align == -1)
  649.     {
  650.       alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
  651.       size = CEIL_ROUND (size, alignment);
  652.     }
  653.   else
  654.     alignment = align / BITS_PER_UNIT;
  655.  
  656.   /* Round frame offset to that alignment.
  657.      We must be careful here, since FRAME_OFFSET might be negative and
  658.      division with a negative dividend isn't as well defined as we might
  659.      like.  So we instead assume that ALIGNMENT is a power of two and
  660.      use logical operations which are unambiguous.  */
  661. #ifdef FRAME_GROWS_DOWNWARD
  662.   frame_offset = FLOOR_ROUND (frame_offset, alignment);
  663. #else
  664.   frame_offset = CEIL_ROUND (frame_offset, alignment);
  665. #endif
  666.  
  667.   /* On a big-endian machine, if we are allocating more space than we will use,
  668.      use the least significant bytes of those that are allocated.  */
  669. #if BYTES_BIG_ENDIAN
  670.   if (mode != BLKmode)
  671.     bigend_correction = size - GET_MODE_SIZE (mode);
  672. #endif
  673.  
  674. #ifdef FRAME_GROWS_DOWNWARD
  675.   frame_offset -= size;
  676. #endif
  677.  
  678.   /* If we have already instantiated virtual registers, return the actual
  679.      address relative to the frame pointer.  */
  680.   if (virtuals_instantiated)
  681.     addr = plus_constant (frame_pointer_rtx,
  682.               (frame_offset + bigend_correction
  683.                + STARTING_FRAME_OFFSET));
  684.   else
  685.     addr = plus_constant (virtual_stack_vars_rtx,
  686.               frame_offset + bigend_correction);
  687.  
  688. #ifndef FRAME_GROWS_DOWNWARD
  689.   frame_offset += size;
  690. #endif
  691.  
  692.   x = gen_rtx (MEM, mode, addr);
  693.  
  694.   stack_slot_list = gen_rtx (EXPR_LIST, VOIDmode, x, stack_slot_list);
  695.  
  696.   return x;
  697. }
  698.  
  699. /* Assign a stack slot in a containing function.
  700.    First three arguments are same as in preceding function.
  701.    The last argument specifies the function to allocate in.  */
  702.  
  703. rtx
  704. assign_outer_stack_local (mode, size, align, function)
  705.      enum machine_mode mode;
  706.      int size;
  707.      int align;
  708.      struct function *function;
  709. {
  710.   register rtx x, addr;
  711.   int bigend_correction = 0;
  712.   int alignment;
  713.  
  714.   /* Allocate in the memory associated with the function in whose frame
  715.      we are assigning.  */
  716.   push_obstacks (function->function_obstack,
  717.          function->function_maybepermanent_obstack);
  718.  
  719.   if (align == 0)
  720.     {
  721.       alignment = GET_MODE_ALIGNMENT (mode) / BITS_PER_UNIT;
  722.       if (mode == BLKmode)
  723.     alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
  724.     }
  725.   else if (align == -1)
  726.     {
  727.       alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
  728.       size = CEIL_ROUND (size, alignment);
  729.     }
  730.   else
  731.     alignment = align / BITS_PER_UNIT;
  732.  
  733.   /* Round frame offset to that alignment.  */
  734. #ifdef FRAME_GROWS_DOWNWARD
  735.   function->frame_offset = FLOOR_ROUND (function->frame_offset, alignment);
  736. #else
  737.   function->frame_offset = CEIL_ROUND (function->frame_offset, alignment);
  738. #endif
  739.  
  740.   /* On a big-endian machine, if we are allocating more space than we will use,
  741.      use the least significant bytes of those that are allocated.  */
  742. #if BYTES_BIG_ENDIAN
  743.   if (mode != BLKmode)
  744.     bigend_correction = size - GET_MODE_SIZE (mode);
  745. #endif
  746.  
  747. #ifdef FRAME_GROWS_DOWNWARD
  748.   function->frame_offset -= size;
  749. #endif
  750.   addr = plus_constant (virtual_stack_vars_rtx,
  751.             function->frame_offset + bigend_correction);
  752. #ifndef FRAME_GROWS_DOWNWARD
  753.   function->frame_offset += size;
  754. #endif
  755.  
  756.   x = gen_rtx (MEM, mode, addr);
  757.  
  758.   function->stack_slot_list
  759.     = gen_rtx (EXPR_LIST, VOIDmode, x, function->stack_slot_list);
  760.  
  761.   pop_obstacks ();
  762.  
  763.   return x;
  764. }
  765.  
  766. /* Allocate a temporary stack slot and record it for possible later
  767.    reuse.
  768.  
  769.    MODE is the machine mode to be given to the returned rtx.
  770.  
  771.    SIZE is the size in units of the space required.  We do no rounding here
  772.    since assign_stack_local will do any required rounding.
  773.  
  774.    KEEP is 1 if this slot is to be retained after a call to
  775.    free_temp_slots.  Automatic variables for a block are allocated
  776.    with this flag.  KEEP is 2, if we allocate a longer term temporary,
  777.    whose lifetime is controlled by CLEANUP_POINT_EXPRs.  */
  778.  
  779. rtx
  780. assign_stack_temp (mode, size, keep)
  781.      enum machine_mode mode;
  782.      int size;
  783.      int keep;
  784. {
  785.   struct temp_slot *p, *best_p = 0;
  786.  
  787.   /* First try to find an available, already-allocated temporary that is the
  788.      exact size we require.  */
  789.   for (p = temp_slots; p; p = p->next)
  790.     if (p->size == size && GET_MODE (p->slot) == mode && ! p->in_use)
  791.       break;
  792.  
  793.   /* If we didn't find, one, try one that is larger than what we want.  We
  794.      find the smallest such.  */
  795.   if (p == 0)
  796.     for (p = temp_slots; p; p = p->next)
  797.       if (p->size > size && GET_MODE (p->slot) == mode && ! p->in_use
  798.       && (best_p == 0 || best_p->size > p->size))
  799.     best_p = p;
  800.  
  801.   /* Make our best, if any, the one to use.  */
  802.   if (best_p)
  803.     {
  804.       /* If there are enough aligned bytes left over, make them into a new
  805.      temp_slot so that the extra bytes don't get wasted.  Do this only
  806.      for BLKmode slots, so that we can be sure of the alignment.  */
  807.       if (GET_MODE (best_p->slot) == BLKmode)
  808.     {
  809.       int alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
  810.       int rounded_size = CEIL_ROUND (size, alignment);
  811.  
  812.       if (best_p->size - rounded_size >= alignment)
  813.         {
  814.           p = (struct temp_slot *) oballoc (sizeof (struct temp_slot));
  815.           p->in_use = 0;
  816.           p->size = best_p->size - rounded_size;
  817.           p->slot = gen_rtx (MEM, BLKmode,
  818.                  plus_constant (XEXP (best_p->slot, 0),
  819.                         rounded_size));
  820.           p->address = 0;
  821.           p->next = temp_slots;
  822.           temp_slots = p;
  823.  
  824.           stack_slot_list = gen_rtx (EXPR_LIST, VOIDmode, p->slot,
  825.                      stack_slot_list);
  826.  
  827.           best_p->size = rounded_size;
  828.         }
  829.     }
  830.  
  831.       p = best_p;
  832.     }
  833.           
  834.   /* If we still didn't find one, make a new temporary.  */
  835.   if (p == 0)
  836.     {
  837.       p = (struct temp_slot *) oballoc (sizeof (struct temp_slot));
  838.       p->size = size;
  839.       /* If the temp slot mode doesn't indicate the alignment,
  840.      use the largest possible, so no one will be disappointed.  */
  841.       p->slot = assign_stack_local (mode, size, mode == BLKmode ? -1 : 0);
  842.       p->address = 0;
  843.       p->next = temp_slots;
  844.       temp_slots = p;
  845.     }
  846.  
  847.   p->in_use = 1;
  848.   p->rtl_expr = sequence_rtl_expr;
  849.   if (keep == 2)
  850.     {
  851.       p->level = target_temp_slot_level;
  852.       p->keep = 0;
  853.     }
  854.   else
  855.     {
  856.       p->level = temp_slot_level;
  857.       p->keep = keep;
  858.     }
  859.   return p->slot;
  860. }
  861.  
  862. /* Combine temporary stack slots which are adjacent on the stack.
  863.  
  864.    This allows for better use of already allocated stack space.  This is only
  865.    done for BLKmode slots because we can be sure that we won't have alignment
  866.    problems in this case.  */
  867.  
  868. void
  869. combine_temp_slots ()
  870. {
  871.   struct temp_slot *p, *q;
  872.   struct temp_slot *prev_p, *prev_q;
  873.   /* Determine where to free back to after this function.  */
  874.   rtx free_pointer = rtx_alloc (CONST_INT);
  875.  
  876.   for (p = temp_slots, prev_p = 0; p; p = prev_p ? prev_p->next : temp_slots)
  877.     {
  878.       int delete_p = 0;
  879.       if (! p->in_use && GET_MODE (p->slot) == BLKmode)
  880.     for (q = p->next, prev_q = p; q; q = prev_q->next)
  881.       {
  882.         int delete_q = 0;
  883.         if (! q->in_use && GET_MODE (q->slot) == BLKmode)
  884.           {
  885.         if (rtx_equal_p (plus_constant (XEXP (p->slot, 0), p->size),
  886.                  XEXP (q->slot, 0)))
  887.           {
  888.             /* Q comes after P; combine Q into P.  */
  889.             p->size += q->size;
  890.             delete_q = 1;
  891.           }
  892.         else if (rtx_equal_p (plus_constant (XEXP (q->slot, 0), q->size),
  893.                       XEXP (p->slot, 0)))
  894.           {
  895.             /* P comes after Q; combine P into Q.  */
  896.             q->size += p->size;
  897.             delete_p = 1;
  898.             break;
  899.           }
  900.           }
  901.         /* Either delete Q or advance past it.  */
  902.         if (delete_q)
  903.           prev_q->next = q->next;
  904.         else
  905.           prev_q = q;
  906.       }
  907.       /* Either delete P or advance past it.  */
  908.       if (delete_p)
  909.     {
  910.       if (prev_p)
  911.         prev_p->next = p->next;
  912.       else
  913.         temp_slots = p->next;
  914.     }
  915.       else
  916.     prev_p = p;
  917.     }
  918.  
  919.   /* Free all the RTL made by plus_constant.  */ 
  920.   rtx_free (free_pointer);
  921. }
  922.  
  923. /* Find the temp slot corresponding to the object at address X.  */
  924.  
  925. static struct temp_slot *
  926. find_temp_slot_from_address (x)
  927.      rtx x;
  928. {
  929.   struct temp_slot *p;
  930.   rtx next;
  931.  
  932.   for (p = temp_slots; p; p = p->next)
  933.     {
  934.       if (! p->in_use)
  935.     continue;
  936.       else if (XEXP (p->slot, 0) == x
  937.            || p->address == x)
  938.     return p;
  939.  
  940.       else if (p->address != 0 && GET_CODE (p->address) == EXPR_LIST)
  941.     for (next = p->address; next; next = XEXP (next, 1))
  942.       if (XEXP (next, 0) == x)
  943.         return p;
  944.     }
  945.  
  946.   return 0;
  947. }
  948.       
  949. /* Indicate that NEW is an alternate way of refering to the temp slot
  950.    that previous was known by OLD.  */
  951.  
  952. void
  953. update_temp_slot_address (old, new)
  954.      rtx old, new;
  955. {
  956.   struct temp_slot *p = find_temp_slot_from_address (old);
  957.  
  958.   /* If none, return.  Else add NEW as an alias.  */
  959.   if (p == 0)
  960.     return;
  961.   else if (p->address == 0)
  962.     p->address = new;
  963.   else
  964.     {
  965.       if (GET_CODE (p->address) != EXPR_LIST)
  966.     p->address = gen_rtx (EXPR_LIST, VOIDmode, p->address, NULL_RTX);
  967.  
  968.       p->address = gen_rtx (EXPR_LIST, VOIDmode, new, p->address);
  969.     }
  970. }
  971.  
  972. /* If X could be a reference to a temporary slot, mark that slot as belonging
  973.    to the to one level higher.  If X matched one of our slots, just mark that
  974.    one.  Otherwise, we can't easily predict which it is, so upgrade all of
  975.    them.  Kept slots need not be touched.
  976.  
  977.    This is called when an ({...}) construct occurs and a statement
  978.    returns a value in memory.  */
  979.  
  980. void
  981. preserve_temp_slots (x)
  982.      rtx x;
  983. {
  984.   struct temp_slot *p;
  985.  
  986.   if (x == 0)
  987.     return;
  988.  
  989.   /* If X is a register that is being used as a pointer, see if we have
  990.      a temporary slot we know it points to.  To be consistent with
  991.      the code below, we really should preserve all non-kept slots
  992.      if we can't find a match, but that seems to be much too costly.  */
  993.   if (GET_CODE (x) == REG && REGNO_POINTER_FLAG (REGNO (x))
  994.       && (p = find_temp_slot_from_address (x)) != 0)
  995.     {
  996.       p->level--;
  997.       return;
  998.     }
  999.     
  1000.   /* If X is not in memory or is at a constant address, it cannot be in
  1001.      a temporary slot.  */
  1002.   if (GET_CODE (x) != MEM || CONSTANT_P (XEXP (x, 0)))
  1003.     return;
  1004.  
  1005.   /* First see if we can find a match.  */
  1006.   p = find_temp_slot_from_address (XEXP (x, 0));
  1007.   if (p != 0)
  1008.     {
  1009.       p->level--;
  1010.       return;
  1011.     }
  1012.  
  1013.   /* Otherwise, preserve all non-kept slots at this level.  */
  1014.   for (p = temp_slots; p; p = p->next)
  1015.     if (p->in_use && p->level == temp_slot_level && ! p->keep)
  1016.       p->level--;
  1017. }
  1018.  
  1019. /* X is the result of an RTL_EXPR.  If it is a temporary slot associated
  1020.    with that RTL_EXPR, promote it into a temporary slot at the present
  1021.    level so it will not be freed when we free slots made in the
  1022.    RTL_EXPR.  */
  1023.  
  1024. void
  1025. preserve_rtl_expr_result (x)
  1026.      rtx x;
  1027. {
  1028.   struct temp_slot *p;
  1029.  
  1030.   /* If X is not in memory or is at a constant address, it cannot be in
  1031.      a temporary slot.  */
  1032.   if (x == 0 || GET_CODE (x) != MEM || CONSTANT_P (XEXP (x, 0)))
  1033.     return;
  1034.  
  1035.   /* If we can find a match, move it to our level.  */
  1036.   for (p = temp_slots; p; p = p->next)
  1037.     if (p->in_use && rtx_equal_p (x, p->slot))
  1038.       {
  1039.     p->level = temp_slot_level;
  1040.     p->rtl_expr = 0;
  1041.     return;
  1042.       }
  1043.  
  1044.   return;
  1045. }
  1046.  
  1047. /* Free all temporaries used so far.  This is normally called at the end
  1048.    of generating code for a statement.  Don't free any temporaries
  1049.    currently in use for an RTL_EXPR that hasn't yet been emitted.
  1050.    We could eventually do better than this since it can be reused while
  1051.    generating the same RTL_EXPR, but this is complex and probably not
  1052.    worthwhile.  */
  1053.  
  1054. void
  1055. free_temp_slots ()
  1056. {
  1057.   struct temp_slot *p;
  1058.  
  1059.   for (p = temp_slots; p; p = p->next)
  1060.     if (p->in_use && p->level == temp_slot_level && ! p->keep
  1061.     && p->rtl_expr == 0)
  1062.       p->in_use = 0;
  1063.  
  1064.   combine_temp_slots ();
  1065. }
  1066.  
  1067. /* Free all temporary slots used in T, an RTL_EXPR node.  */
  1068.  
  1069. void
  1070. free_temps_for_rtl_expr (t)
  1071.      tree t;
  1072. {
  1073.   struct temp_slot *p;
  1074.  
  1075.   for (p = temp_slots; p; p = p->next)
  1076.     if (p->rtl_expr == t)
  1077.       p->in_use = 0;
  1078.  
  1079.   combine_temp_slots ();
  1080. }
  1081.  
  1082. /* Push deeper into the nesting level for stack temporaries.  */
  1083.  
  1084. void
  1085. push_temp_slots ()
  1086. {
  1087.   temp_slot_level++;
  1088. }
  1089.  
  1090. /* Pop a temporary nesting level.  All slots in use in the current level
  1091.    are freed.  */
  1092.  
  1093. void
  1094. pop_temp_slots ()
  1095. {
  1096.   struct temp_slot *p;
  1097.  
  1098.   for (p = temp_slots; p; p = p->next)
  1099.     if (p->in_use && p->level == temp_slot_level && p->rtl_expr == 0)
  1100.       p->in_use = 0;
  1101.  
  1102.   combine_temp_slots ();
  1103.  
  1104.   temp_slot_level--;
  1105. }
  1106.  
  1107. /* Retroactively move an auto variable from a register to a stack slot.
  1108.    This is done when an address-reference to the variable is seen.  */
  1109.  
  1110. void
  1111. put_var_into_stack (decl)
  1112.      tree decl;
  1113. {
  1114.   register rtx reg;
  1115.   enum machine_mode promoted_mode, decl_mode;
  1116.   struct function *function = 0;
  1117.   tree context;
  1118.  
  1119.   if (output_bytecode)
  1120.     return;
  1121.   
  1122.   context = decl_function_context (decl);
  1123.  
  1124.   /* Get the current rtl used for this object and it's original mode.  */
  1125.   reg = TREE_CODE (decl) == SAVE_EXPR ? SAVE_EXPR_RTL (decl) : DECL_RTL (decl);
  1126.  
  1127.   /* No need to do anything if decl has no rtx yet
  1128.      since in that case caller is setting TREE_ADDRESSABLE
  1129.      and a stack slot will be assigned when the rtl is made.  */
  1130.   if (reg == 0)
  1131.     return;
  1132.  
  1133.   /* Get the declared mode for this object.  */
  1134.   decl_mode = (TREE_CODE (decl) == SAVE_EXPR ? TYPE_MODE (TREE_TYPE (decl))
  1135.            : DECL_MODE (decl));
  1136.   /* Get the mode it's actually stored in.  */
  1137.   promoted_mode = GET_MODE (reg);
  1138.  
  1139.   /* If this variable comes from an outer function,
  1140.      find that function's saved context.  */
  1141.   if (context != current_function_decl)
  1142.     for (function = outer_function_chain; function; function = function->next)
  1143.       if (function->decl == context)
  1144.     break;
  1145.  
  1146.   /* If this is a variable-size object with a pseudo to address it,
  1147.      put that pseudo into the stack, if the var is nonlocal.  */
  1148.   if (DECL_NONLOCAL (decl)
  1149.       && GET_CODE (reg) == MEM
  1150.       && GET_CODE (XEXP (reg, 0)) == REG
  1151.       && REGNO (XEXP (reg, 0)) > LAST_VIRTUAL_REGISTER)
  1152.     {
  1153.       reg = XEXP (reg, 0);
  1154.       decl_mode = promoted_mode = GET_MODE (reg);
  1155.     }
  1156.  
  1157.   /* Now we should have a value that resides in one or more pseudo regs.  */
  1158.  
  1159.   if (GET_CODE (reg) == REG)
  1160.     put_reg_into_stack (function, reg, TREE_TYPE (decl),
  1161.             promoted_mode, decl_mode);
  1162.   else if (GET_CODE (reg) == CONCAT)
  1163.     {
  1164.       /* A CONCAT contains two pseudos; put them both in the stack.
  1165.      We do it so they end up consecutive.  */
  1166.       enum machine_mode part_mode = GET_MODE (XEXP (reg, 0));
  1167.       tree part_type = TREE_TYPE (TREE_TYPE (decl));
  1168. #ifdef STACK_GROWS_DOWNWARD
  1169.       /* Since part 0 should have a lower address, do it second.  */
  1170.       put_reg_into_stack (function, XEXP (reg, 1),
  1171.               part_type, part_mode, part_mode);
  1172.       put_reg_into_stack (function, XEXP (reg, 0),
  1173.               part_type, part_mode, part_mode);
  1174. #else
  1175.       put_reg_into_stack (function, XEXP (reg, 0),
  1176.               part_type, part_mode, part_mode);
  1177.       put_reg_into_stack (function, XEXP (reg, 1),
  1178.               part_type, part_mode, part_mode);
  1179. #endif
  1180.  
  1181.       /* Change the CONCAT into a combined MEM for both parts.  */
  1182.       PUT_CODE (reg, MEM);
  1183.       /* The two parts are in memory order already.
  1184.      Use the lower parts address as ours.  */
  1185.       XEXP (reg, 0) = XEXP (XEXP (reg, 0), 0);
  1186.       /* Prevent sharing of rtl that might lose.  */
  1187.       if (GET_CODE (XEXP (reg, 0)) == PLUS)
  1188.     XEXP (reg, 0) = copy_rtx (XEXP (reg, 0));
  1189.     }
  1190. }
  1191.  
  1192. /* Subroutine of put_var_into_stack.  This puts a single pseudo reg REG
  1193.    into the stack frame of FUNCTION (0 means the current function).
  1194.    DECL_MODE is the machine mode of the user-level data type.
  1195.    PROMOTED_MODE is the machine mode of the register.  */
  1196.  
  1197. static void
  1198. put_reg_into_stack (function, reg, type, promoted_mode, decl_mode)
  1199.      struct function *function;
  1200.      rtx reg;
  1201.      tree type;
  1202.      enum machine_mode promoted_mode, decl_mode;
  1203. {
  1204.   rtx new = 0;
  1205.  
  1206.   if (function)
  1207.     {
  1208.       if (REGNO (reg) < function->max_parm_reg)
  1209.     new = function->parm_reg_stack_loc[REGNO (reg)];
  1210.       if (new == 0)
  1211.     new = assign_outer_stack_local (decl_mode, GET_MODE_SIZE (decl_mode),
  1212.                     0, function);
  1213.     }
  1214.   else
  1215.     {
  1216.       if (REGNO (reg) < max_parm_reg)
  1217.     new = parm_reg_stack_loc[REGNO (reg)];
  1218.       if (new == 0)
  1219.     new = assign_stack_local (decl_mode, GET_MODE_SIZE (decl_mode), 0);
  1220.     }
  1221.  
  1222.   XEXP (reg, 0) = XEXP (new, 0);
  1223.   /* `volatil' bit means one thing for MEMs, another entirely for REGs.  */
  1224.   REG_USERVAR_P (reg) = 0;
  1225.   PUT_CODE (reg, MEM);
  1226.   PUT_MODE (reg, decl_mode);
  1227.  
  1228.   /* If this is a memory ref that contains aggregate components,
  1229.      mark it as such for cse and loop optimize.  */
  1230.   MEM_IN_STRUCT_P (reg) = AGGREGATE_TYPE_P (type);
  1231.  
  1232.   /* Now make sure that all refs to the variable, previously made
  1233.      when it was a register, are fixed up to be valid again.  */
  1234.   if (function)
  1235.     {
  1236.       struct var_refs_queue *temp;
  1237.  
  1238.       /* Variable is inherited; fix it up when we get back to its function.  */
  1239.       push_obstacks (function->function_obstack,
  1240.              function->function_maybepermanent_obstack);
  1241.  
  1242.       /* See comment in restore_tree_status in tree.c for why this needs to be
  1243.      on saveable obstack.  */
  1244.       temp
  1245.     = (struct var_refs_queue *) savealloc (sizeof (struct var_refs_queue));
  1246.       temp->modified = reg;
  1247.       temp->promoted_mode = promoted_mode;
  1248.       temp->unsignedp = TREE_UNSIGNED (type);
  1249.       temp->next = function->fixup_var_refs_queue;
  1250.       function->fixup_var_refs_queue = temp;
  1251.       pop_obstacks ();
  1252.     }
  1253.   else
  1254.     /* Variable is local; fix it up now.  */
  1255.     fixup_var_refs (reg, promoted_mode, TREE_UNSIGNED (type));
  1256. }
  1257.  
  1258. static void
  1259. fixup_var_refs (var, promoted_mode, unsignedp)
  1260.      rtx var;
  1261.      enum machine_mode promoted_mode;
  1262.      int unsignedp;
  1263. {
  1264.   tree pending;
  1265.   rtx first_insn = get_insns ();
  1266.   struct sequence_stack *stack = sequence_stack;
  1267.   tree rtl_exps = rtl_expr_chain;
  1268.  
  1269.   /* Must scan all insns for stack-refs that exceed the limit.  */
  1270.   fixup_var_refs_insns (var, promoted_mode, unsignedp, first_insn, stack == 0);
  1271.  
  1272.   /* Scan all pending sequences too.  */
  1273.   for (; stack; stack = stack->next)
  1274.     {
  1275.       push_to_sequence (stack->first);
  1276.       fixup_var_refs_insns (var, promoted_mode, unsignedp,
  1277.                 stack->first, stack->next != 0);
  1278.       /* Update remembered end of sequence
  1279.      in case we added an insn at the end.  */
  1280.       stack->last = get_last_insn ();
  1281.       end_sequence ();
  1282.     }
  1283.  
  1284.   /* Scan all waiting RTL_EXPRs too.  */
  1285.   for (pending = rtl_exps; pending; pending = TREE_CHAIN (pending))
  1286.     {
  1287.       rtx seq = RTL_EXPR_SEQUENCE (TREE_VALUE (pending));
  1288.       if (seq != const0_rtx && seq != 0)
  1289.     {
  1290.       push_to_sequence (seq);
  1291.       fixup_var_refs_insns (var, promoted_mode, unsignedp, seq, 0);
  1292.       end_sequence ();
  1293.     }
  1294.     }
  1295. }
  1296.  
  1297. /* REPLACEMENTS is a pointer to a list of the struct fixup_replacement and X is
  1298.    some part of an insn.  Return a struct fixup_replacement whose OLD
  1299.    value is equal to X.  Allocate a new structure if no such entry exists. */
  1300.  
  1301. static struct fixup_replacement *
  1302. find_fixup_replacement (replacements, x)
  1303.      struct fixup_replacement **replacements;
  1304.      rtx x;
  1305. {
  1306.   struct fixup_replacement *p;
  1307.  
  1308.   /* See if we have already replaced this.  */
  1309.   for (p = *replacements; p && p->old != x; p = p->next)
  1310.     ;
  1311.  
  1312.   if (p == 0)
  1313.     {
  1314.       p = (struct fixup_replacement *) oballoc (sizeof (struct fixup_replacement));
  1315.       p->old = x;
  1316.       p->new = 0;
  1317.       p->next = *replacements;
  1318.       *replacements = p;
  1319.     }
  1320.  
  1321.   return p;
  1322. }
  1323.  
  1324. /* Scan the insn-chain starting with INSN for refs to VAR
  1325.    and fix them up.  TOPLEVEL is nonzero if this chain is the
  1326.    main chain of insns for the current function.  */
  1327.  
  1328. static void
  1329. fixup_var_refs_insns (var, promoted_mode, unsignedp, insn, toplevel)
  1330.      rtx var;
  1331.      enum machine_mode promoted_mode;
  1332.      int unsignedp;
  1333.      rtx insn;
  1334.      int toplevel;
  1335. {
  1336.   rtx call_dest = 0;
  1337.  
  1338.   while (insn)
  1339.     {
  1340.       rtx next = NEXT_INSN (insn);
  1341.       rtx note;
  1342.       if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
  1343.     {
  1344.       /* If this is a CLOBBER of VAR, delete it.
  1345.  
  1346.          If it has a REG_LIBCALL note, delete the REG_LIBCALL
  1347.          and REG_RETVAL notes too.  */
  1348.       if (GET_CODE (PATTERN (insn)) == CLOBBER
  1349.           && XEXP (PATTERN (insn), 0) == var)
  1350.         {
  1351.           if ((note = find_reg_note (insn, REG_LIBCALL, NULL_RTX)) != 0)
  1352.         /* The REG_LIBCALL note will go away since we are going to
  1353.            turn INSN into a NOTE, so just delete the
  1354.            corresponding REG_RETVAL note.  */
  1355.         remove_note (XEXP (note, 0),
  1356.                  find_reg_note (XEXP (note, 0), REG_RETVAL,
  1357.                         NULL_RTX));
  1358.  
  1359.           /* In unoptimized compilation, we shouldn't call delete_insn
  1360.          except in jump.c doing warnings.  */
  1361.           PUT_CODE (insn, NOTE);
  1362.           NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
  1363.           NOTE_SOURCE_FILE (insn) = 0;
  1364.         }
  1365.  
  1366.       /* The insn to load VAR from a home in the arglist
  1367.          is now a no-op.  When we see it, just delete it.  */
  1368.       else if (toplevel
  1369.            && GET_CODE (PATTERN (insn)) == SET
  1370.            && SET_DEST (PATTERN (insn)) == var
  1371.            /* If this represents the result of an insn group,
  1372.               don't delete the insn.  */
  1373.            && find_reg_note (insn, REG_RETVAL, NULL_RTX) == 0
  1374.            && rtx_equal_p (SET_SRC (PATTERN (insn)), var))
  1375.         {
  1376.           /* In unoptimized compilation, we shouldn't call delete_insn
  1377.          except in jump.c doing warnings.  */
  1378.           PUT_CODE (insn, NOTE);
  1379.           NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
  1380.           NOTE_SOURCE_FILE (insn) = 0;
  1381.           if (insn == last_parm_insn)
  1382.         last_parm_insn = PREV_INSN (next);
  1383.         }
  1384.       else
  1385.         {
  1386.           struct fixup_replacement *replacements = 0;
  1387.           rtx next_insn = NEXT_INSN (insn);
  1388.  
  1389. #ifdef SMALL_REGISTER_CLASSES
  1390.           /* If the insn that copies the results of a CALL_INSN
  1391.          into a pseudo now references VAR, we have to use an
  1392.          intermediate pseudo since we want the life of the
  1393.          return value register to be only a single insn.
  1394.  
  1395.          If we don't use an intermediate pseudo, such things as
  1396.          address computations to make the address of VAR valid
  1397.          if it is not can be placed beween the CALL_INSN and INSN.
  1398.  
  1399.          To make sure this doesn't happen, we record the destination
  1400.          of the CALL_INSN and see if the next insn uses both that
  1401.          and VAR.  */
  1402.  
  1403.           if (call_dest != 0 && GET_CODE (insn) == INSN
  1404.           && reg_mentioned_p (var, PATTERN (insn))
  1405.           && reg_mentioned_p (call_dest, PATTERN (insn)))
  1406.         {
  1407.           rtx temp = gen_reg_rtx (GET_MODE (call_dest));
  1408.  
  1409.           emit_insn_before (gen_move_insn (temp, call_dest), insn);
  1410.  
  1411.           PATTERN (insn) = replace_rtx (PATTERN (insn),
  1412.                         call_dest, temp);
  1413.         }
  1414.           
  1415.           if (GET_CODE (insn) == CALL_INSN
  1416.           && GET_CODE (PATTERN (insn)) == SET)
  1417.         call_dest = SET_DEST (PATTERN (insn));
  1418.           else if (GET_CODE (insn) == CALL_INSN
  1419.                && GET_CODE (PATTERN (insn)) == PARALLEL
  1420.                && GET_CODE (XVECEXP (PATTERN (insn), 0, 0)) == SET)
  1421.         call_dest = SET_DEST (XVECEXP (PATTERN (insn), 0, 0));
  1422.           else
  1423.         call_dest = 0;
  1424. #endif
  1425.  
  1426.           /* See if we have to do anything to INSN now that VAR is in
  1427.          memory.  If it needs to be loaded into a pseudo, use a single
  1428.          pseudo for the entire insn in case there is a MATCH_DUP
  1429.          between two operands.  We pass a pointer to the head of
  1430.          a list of struct fixup_replacements.  If fixup_var_refs_1
  1431.          needs to allocate pseudos or replacement MEMs (for SUBREGs),
  1432.          it will record them in this list.
  1433.          
  1434.          If it allocated a pseudo for any replacement, we copy into
  1435.          it here.  */
  1436.  
  1437.           fixup_var_refs_1 (var, promoted_mode, &PATTERN (insn), insn,
  1438.                 &replacements);
  1439.  
  1440.           /* If this is last_parm_insn, and any instructions were output
  1441.          after it to fix it up, then we must set last_parm_insn to
  1442.          the last such instruction emitted.  */
  1443.           if (insn == last_parm_insn)
  1444.         last_parm_insn = PREV_INSN (next_insn);
  1445.  
  1446.           while (replacements)
  1447.         {
  1448.           if (GET_CODE (replacements->new) == REG)
  1449.             {
  1450.               rtx insert_before;
  1451.               rtx seq;
  1452.  
  1453.               /* OLD might be a (subreg (mem)).  */
  1454.               if (GET_CODE (replacements->old) == SUBREG)
  1455.             replacements->old
  1456.               = fixup_memory_subreg (replacements->old, insn, 0);
  1457.               else
  1458.             replacements->old
  1459.               = fixup_stack_1 (replacements->old, insn);
  1460.  
  1461.               insert_before = insn;
  1462.  
  1463.               /* If we are changing the mode, do a conversion.
  1464.              This might be wasteful, but combine.c will
  1465.              eliminate much of the waste.  */
  1466.  
  1467.               if (GET_MODE (replacements->new)
  1468.               != GET_MODE (replacements->old))
  1469.             {
  1470.               start_sequence ();
  1471.               convert_move (replacements->new,
  1472.                     replacements->old, unsignedp);
  1473.               seq = gen_sequence ();
  1474.               end_sequence ();
  1475.             }
  1476.               else
  1477.             seq = gen_move_insn (replacements->new,
  1478.                          replacements->old);
  1479.  
  1480.               emit_insn_before (seq, insert_before);
  1481.             }
  1482.  
  1483.           replacements = replacements->next;
  1484.         }
  1485.         }
  1486.  
  1487.       /* Also fix up any invalid exprs in the REG_NOTES of this insn.
  1488.          But don't touch other insns referred to by reg-notes;
  1489.          we will get them elsewhere.  */
  1490.       for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
  1491.         if (GET_CODE (note) != INSN_LIST)
  1492.           XEXP (note, 0)
  1493.         = walk_fixup_memory_subreg (XEXP (note, 0), insn, 1);
  1494.     }
  1495.       insn = next;
  1496.     }
  1497. }
  1498.  
  1499. /* VAR is a MEM that used to be a pseudo register with mode PROMOTED_MODE.
  1500.    See if the rtx expression at *LOC in INSN needs to be changed.  
  1501.  
  1502.    REPLACEMENTS is a pointer to a list head that starts out zero, but may
  1503.    contain a list of original rtx's and replacements. If we find that we need
  1504.    to modify this insn by replacing a memory reference with a pseudo or by
  1505.    making a new MEM to implement a SUBREG, we consult that list to see if
  1506.    we have already chosen a replacement. If none has already been allocated,
  1507.    we allocate it and update the list.  fixup_var_refs_insns will copy VAR
  1508.    or the SUBREG, as appropriate, to the pseudo.  */
  1509.  
  1510. static void
  1511. fixup_var_refs_1 (var, promoted_mode, loc, insn, replacements)
  1512.      register rtx var;
  1513.      enum machine_mode promoted_mode;
  1514.      register rtx *loc;
  1515.      rtx insn;
  1516.      struct fixup_replacement **replacements;
  1517. {
  1518.   register int i;
  1519.   register rtx x = *loc;
  1520.   RTX_CODE code = GET_CODE (x);
  1521.   register char *fmt;
  1522.   register rtx tem, tem1;
  1523.   struct fixup_replacement *replacement;
  1524.  
  1525.   switch (code)
  1526.     {
  1527.     case MEM:
  1528.       if (var == x)
  1529.     {
  1530.       /* If we already have a replacement, use it.  Otherwise, 
  1531.          try to fix up this address in case it is invalid.  */
  1532.  
  1533.       replacement = find_fixup_replacement (replacements, var);
  1534.       if (replacement->new)
  1535.         {
  1536.           *loc = replacement->new;
  1537.           return;
  1538.         }
  1539.  
  1540.       *loc = replacement->new = x = fixup_stack_1 (x, insn);
  1541.  
  1542.       /* Unless we are forcing memory to register or we changed the mode,
  1543.          we can leave things the way they are if the insn is valid.  */
  1544.          
  1545.       INSN_CODE (insn) = -1;
  1546.       if (! flag_force_mem && GET_MODE (x) == promoted_mode
  1547.           && recog_memoized (insn) >= 0)
  1548.         return;
  1549.  
  1550.       *loc = replacement->new = gen_reg_rtx (promoted_mode);
  1551.       return;
  1552.     }
  1553.  
  1554.       /* If X contains VAR, we need to unshare it here so that we update
  1555.      each occurrence separately.  But all identical MEMs in one insn
  1556.      must be replaced with the same rtx because of the possibility of
  1557.      MATCH_DUPs.  */
  1558.  
  1559.       if (reg_mentioned_p (var, x))
  1560.     {
  1561.       replacement = find_fixup_replacement (replacements, x);
  1562.       if (replacement->new == 0)
  1563.         replacement->new = copy_most_rtx (x, var);
  1564.  
  1565.       *loc = x = replacement->new;
  1566.     }
  1567.       break;
  1568.  
  1569.     case REG:
  1570.     case CC0:
  1571.     case PC:
  1572.     case CONST_INT:
  1573.     case CONST:
  1574.     case SYMBOL_REF:
  1575.     case LABEL_REF:
  1576.     case CONST_DOUBLE:
  1577.       return;
  1578.  
  1579.     case SIGN_EXTRACT:
  1580.     case ZERO_EXTRACT:
  1581.       /* Note that in some cases those types of expressions are altered
  1582.      by optimize_bit_field, and do not survive to get here.  */
  1583.       if (XEXP (x, 0) == var
  1584.       || (GET_CODE (XEXP (x, 0)) == SUBREG
  1585.           && SUBREG_REG (XEXP (x, 0)) == var))
  1586.     {
  1587.       /* Get TEM as a valid MEM in the mode presently in the insn.
  1588.  
  1589.          We don't worry about the possibility of MATCH_DUP here; it
  1590.          is highly unlikely and would be tricky to handle.  */
  1591.  
  1592.       tem = XEXP (x, 0);
  1593.       if (GET_CODE (tem) == SUBREG)
  1594.         tem = fixup_memory_subreg (tem, insn, 1);
  1595.       tem = fixup_stack_1 (tem, insn);
  1596.  
  1597.       /* Unless we want to load from memory, get TEM into the proper mode
  1598.          for an extract from memory.  This can only be done if the
  1599.          extract is at a constant position and length.  */
  1600.  
  1601.       if (! flag_force_mem && GET_CODE (XEXP (x, 1)) == CONST_INT
  1602.           && GET_CODE (XEXP (x, 2)) == CONST_INT
  1603.           && ! mode_dependent_address_p (XEXP (tem, 0))
  1604.           && ! MEM_VOLATILE_P (tem))
  1605.         {
  1606.           enum machine_mode wanted_mode = VOIDmode;
  1607.           enum machine_mode is_mode = GET_MODE (tem);
  1608.           int width = INTVAL (XEXP (x, 1));
  1609.           int pos = INTVAL (XEXP (x, 2));
  1610.  
  1611. #ifdef HAVE_extzv
  1612.           if (GET_CODE (x) == ZERO_EXTRACT)
  1613.         wanted_mode = insn_operand_mode[(int) CODE_FOR_extzv][1];
  1614. #endif
  1615. #ifdef HAVE_extv
  1616.           if (GET_CODE (x) == SIGN_EXTRACT)
  1617.         wanted_mode = insn_operand_mode[(int) CODE_FOR_extv][1];
  1618. #endif
  1619.           /* If we have a narrower mode, we can do something.  */
  1620.           if (wanted_mode != VOIDmode
  1621.           && GET_MODE_SIZE (wanted_mode) < GET_MODE_SIZE (is_mode))
  1622.         {
  1623.           int offset = pos / BITS_PER_UNIT;
  1624.           rtx old_pos = XEXP (x, 2);
  1625.           rtx newmem;
  1626.  
  1627.           /* If the bytes and bits are counted differently, we
  1628.              must adjust the offset.  */
  1629. #if BYTES_BIG_ENDIAN != BITS_BIG_ENDIAN
  1630.           offset = (GET_MODE_SIZE (is_mode)
  1631.                 - GET_MODE_SIZE (wanted_mode) - offset);
  1632. #endif
  1633.  
  1634.           pos %= GET_MODE_BITSIZE (wanted_mode);
  1635.  
  1636.           newmem = gen_rtx (MEM, wanted_mode,
  1637.                     plus_constant (XEXP (tem, 0), offset));
  1638.           RTX_UNCHANGING_P (newmem) = RTX_UNCHANGING_P (tem);
  1639.           MEM_VOLATILE_P (newmem) = MEM_VOLATILE_P (tem);
  1640.           MEM_IN_STRUCT_P (newmem) = MEM_IN_STRUCT_P (tem);
  1641.  
  1642.           /* Make the change and see if the insn remains valid.  */
  1643.           INSN_CODE (insn) = -1;
  1644.           XEXP (x, 0) = newmem;
  1645.           XEXP (x, 2) = GEN_INT (pos);
  1646.  
  1647.           if (recog_memoized (insn) >= 0)
  1648.             return;
  1649.  
  1650.           /* Otherwise, restore old position.  XEXP (x, 0) will be
  1651.              restored later.  */
  1652.           XEXP (x, 2) = old_pos;
  1653.         }
  1654.         }
  1655.  
  1656.       /* If we get here, the bitfield extract insn can't accept a memory
  1657.          reference.  Copy the input into a register.  */
  1658.  
  1659.       tem1 = gen_reg_rtx (GET_MODE (tem));
  1660.       emit_insn_before (gen_move_insn (tem1, tem), insn);
  1661.       XEXP (x, 0) = tem1;
  1662.       return;
  1663.     }
  1664.       break;
  1665.           
  1666.     case SUBREG:
  1667.       if (SUBREG_REG (x) == var)
  1668.     {
  1669.       /* If this is a special SUBREG made because VAR was promoted
  1670.          from a wider mode, replace it with VAR and call ourself
  1671.          recursively, this time saying that the object previously
  1672.          had its current mode (by virtue of the SUBREG).  */
  1673.  
  1674.       if (SUBREG_PROMOTED_VAR_P (x))
  1675.         {
  1676.           *loc = var;
  1677.           fixup_var_refs_1 (var, GET_MODE (var), loc, insn, replacements);
  1678.           return;
  1679.         }
  1680.  
  1681.       /* If this SUBREG makes VAR wider, it has become a paradoxical
  1682.          SUBREG with VAR in memory, but these aren't allowed at this 
  1683.          stage of the compilation.  So load VAR into a pseudo and take
  1684.          a SUBREG of that pseudo.  */
  1685.       if (GET_MODE_SIZE (GET_MODE (x)) > GET_MODE_SIZE (GET_MODE (var)))
  1686.         {
  1687.           replacement = find_fixup_replacement (replacements, var);
  1688.           if (replacement->new == 0)
  1689.         replacement->new = gen_reg_rtx (GET_MODE (var));
  1690.           SUBREG_REG (x) = replacement->new;
  1691.           return;
  1692.         }
  1693.  
  1694.       /* See if we have already found a replacement for this SUBREG.
  1695.          If so, use it.  Otherwise, make a MEM and see if the insn
  1696.          is recognized.  If not, or if we should force MEM into a register,
  1697.          make a pseudo for this SUBREG.  */
  1698.       replacement = find_fixup_replacement (replacements, x);
  1699.       if (replacement->new)
  1700.         {
  1701.           *loc = replacement->new;
  1702.           return;
  1703.         }
  1704.       
  1705.       replacement->new = *loc = fixup_memory_subreg (x, insn, 0);
  1706.  
  1707.       INSN_CODE (insn) = -1;
  1708.       if (! flag_force_mem && recog_memoized (insn) >= 0)
  1709.         return;
  1710.  
  1711.       *loc = replacement->new = gen_reg_rtx (GET_MODE (x));
  1712.       return;
  1713.     }
  1714.       break;
  1715.  
  1716.     case SET:
  1717.       /* First do special simplification of bit-field references.  */
  1718.       if (GET_CODE (SET_DEST (x)) == SIGN_EXTRACT
  1719.       || GET_CODE (SET_DEST (x)) == ZERO_EXTRACT)
  1720.     optimize_bit_field (x, insn, 0);
  1721.       if (GET_CODE (SET_SRC (x)) == SIGN_EXTRACT
  1722.       || GET_CODE (SET_SRC (x)) == ZERO_EXTRACT)
  1723.     optimize_bit_field (x, insn, NULL_PTR);
  1724.  
  1725.       /* If SET_DEST is now a paradoxical SUBREG, put the result of this
  1726.      insn into a pseudo and store the low part of the pseudo into VAR. */
  1727.       if (GET_CODE (SET_DEST (x)) == SUBREG
  1728.       && SUBREG_REG (SET_DEST (x)) == var
  1729.       && (GET_MODE_SIZE (GET_MODE (SET_DEST (x)))
  1730.           > GET_MODE_SIZE (GET_MODE (var))))
  1731.     {
  1732.       SET_DEST (x) = tem = gen_reg_rtx (GET_MODE (SET_DEST (x)));
  1733.       emit_insn_after (gen_move_insn (var, gen_lowpart (GET_MODE (var),
  1734.                                 tem)),
  1735.                insn);
  1736.       break;
  1737.     }
  1738.       
  1739.       {
  1740.     rtx dest = SET_DEST (x);
  1741.     rtx src = SET_SRC (x);
  1742.     rtx outerdest = dest;
  1743.  
  1744.     while (GET_CODE (dest) == SUBREG || GET_CODE (dest) == STRICT_LOW_PART
  1745.            || GET_CODE (dest) == SIGN_EXTRACT
  1746.            || GET_CODE (dest) == ZERO_EXTRACT)
  1747.       dest = XEXP (dest, 0);
  1748.  
  1749.     if (GET_CODE (src) == SUBREG)
  1750.       src = XEXP (src, 0);
  1751.  
  1752.     /* If VAR does not appear at the top level of the SET
  1753.        just scan the lower levels of the tree.  */
  1754.  
  1755.         if (src != var && dest != var)
  1756.       break;
  1757.  
  1758.     /* We will need to rerecognize this insn.  */
  1759.     INSN_CODE (insn) = -1;
  1760.  
  1761. #ifdef HAVE_insv
  1762.     if (GET_CODE (outerdest) == ZERO_EXTRACT && dest == var)
  1763.       {
  1764.         /* Since this case will return, ensure we fixup all the
  1765.            operands here.  */
  1766.         fixup_var_refs_1 (var, promoted_mode, &XEXP (outerdest, 1),
  1767.                   insn, replacements);
  1768.         fixup_var_refs_1 (var, promoted_mode, &XEXP (outerdest, 2),
  1769.                   insn, replacements);
  1770.         fixup_var_refs_1 (var, promoted_mode, &SET_SRC (x),
  1771.                   insn, replacements);
  1772.  
  1773.         tem = XEXP (outerdest, 0);
  1774.  
  1775.         /* Clean up (SUBREG:SI (MEM:mode ...) 0)
  1776.            that may appear inside a ZERO_EXTRACT.
  1777.            This was legitimate when the MEM was a REG.  */
  1778.         if (GET_CODE (tem) == SUBREG
  1779.         && SUBREG_REG (tem) == var)
  1780.           tem = fixup_memory_subreg (tem, insn, 1);
  1781.         else
  1782.           tem = fixup_stack_1 (tem, insn);
  1783.  
  1784.         if (GET_CODE (XEXP (outerdest, 1)) == CONST_INT
  1785.         && GET_CODE (XEXP (outerdest, 2)) == CONST_INT
  1786.         && ! mode_dependent_address_p (XEXP (tem, 0))
  1787.         && ! MEM_VOLATILE_P (tem))
  1788.           {
  1789.         enum machine_mode wanted_mode
  1790.           = insn_operand_mode[(int) CODE_FOR_insv][0];
  1791.         enum machine_mode is_mode = GET_MODE (tem);
  1792.         int width = INTVAL (XEXP (outerdest, 1));
  1793.         int pos = INTVAL (XEXP (outerdest, 2));
  1794.  
  1795.         /* If we have a narrower mode, we can do something.  */
  1796.         if (GET_MODE_SIZE (wanted_mode) < GET_MODE_SIZE (is_mode))
  1797.           {
  1798.             int offset = pos / BITS_PER_UNIT;
  1799.             rtx old_pos = XEXP (outerdest, 2);
  1800.             rtx newmem;
  1801.  
  1802. #if BYTES_BIG_ENDIAN != BITS_BIG_ENDIAN
  1803.             offset = (GET_MODE_SIZE (is_mode)
  1804.                   - GET_MODE_SIZE (wanted_mode) - offset);
  1805. #endif
  1806.  
  1807.             pos %= GET_MODE_BITSIZE (wanted_mode);
  1808.  
  1809.             newmem = gen_rtx (MEM, wanted_mode,
  1810.                       plus_constant (XEXP (tem, 0), offset));
  1811.             RTX_UNCHANGING_P (newmem) = RTX_UNCHANGING_P (tem);
  1812.             MEM_VOLATILE_P (newmem) = MEM_VOLATILE_P (tem);
  1813.             MEM_IN_STRUCT_P (newmem) = MEM_IN_STRUCT_P (tem);
  1814.  
  1815.             /* Make the change and see if the insn remains valid.  */
  1816.             INSN_CODE (insn) = -1;
  1817.             XEXP (outerdest, 0) = newmem;
  1818.             XEXP (outerdest, 2) = GEN_INT (pos);
  1819.             
  1820.             if (recog_memoized (insn) >= 0)
  1821.               return;
  1822.             
  1823.             /* Otherwise, restore old position.  XEXP (x, 0) will be
  1824.                restored later.  */
  1825.             XEXP (outerdest, 2) = old_pos;
  1826.           }
  1827.           }
  1828.  
  1829.         /* If we get here, the bit-field store doesn't allow memory
  1830.            or isn't located at a constant position.  Load the value into
  1831.            a register, do the store, and put it back into memory.  */
  1832.  
  1833.         tem1 = gen_reg_rtx (GET_MODE (tem));
  1834.         emit_insn_before (gen_move_insn (tem1, tem), insn);
  1835.         emit_insn_after (gen_move_insn (tem, tem1), insn);
  1836.         XEXP (outerdest, 0) = tem1;
  1837.         return;
  1838.       }
  1839. #endif
  1840.  
  1841.     /* STRICT_LOW_PART is a no-op on memory references
  1842.        and it can cause combinations to be unrecognizable,
  1843.        so eliminate it.  */
  1844.  
  1845.     if (dest == var && GET_CODE (SET_DEST (x)) == STRICT_LOW_PART)
  1846.       SET_DEST (x) = XEXP (SET_DEST (x), 0);
  1847.  
  1848.     /* A valid insn to copy VAR into or out of a register
  1849.        must be left alone, to avoid an infinite loop here.
  1850.        If the reference to VAR is by a subreg, fix that up,
  1851.        since SUBREG is not valid for a memref.
  1852.        Also fix up the address of the stack slot.
  1853.  
  1854.        Note that we must not try to recognize the insn until
  1855.        after we know that we have valid addresses and no
  1856.        (subreg (mem ...) ...) constructs, since these interfere
  1857.        with determining the validity of the insn.  */
  1858.  
  1859.     if ((SET_SRC (x) == var
  1860.          || (GET_CODE (SET_SRC (x)) == SUBREG
  1861.          && SUBREG_REG (SET_SRC (x)) == var))
  1862.         && (GET_CODE (SET_DEST (x)) == REG
  1863.         || (GET_CODE (SET_DEST (x)) == SUBREG
  1864.             && GET_CODE (SUBREG_REG (SET_DEST (x))) == REG))
  1865.         && x == single_set (PATTERN (insn)))
  1866.       {
  1867.         rtx pat;
  1868.  
  1869.         replacement = find_fixup_replacement (replacements, SET_SRC (x));
  1870.         if (replacement->new)
  1871.           SET_SRC (x) = replacement->new;
  1872.         else if (GET_CODE (SET_SRC (x)) == SUBREG)
  1873.           SET_SRC (x) = replacement->new
  1874.         = fixup_memory_subreg (SET_SRC (x), insn, 0);
  1875.         else
  1876.           SET_SRC (x) = replacement->new
  1877.         = fixup_stack_1 (SET_SRC (x), insn);
  1878.  
  1879.         if (recog_memoized (insn) >= 0)
  1880.           return;
  1881.  
  1882.         /* INSN is not valid, but we know that we want to
  1883.            copy SET_SRC (x) to SET_DEST (x) in some way.  So
  1884.            we generate the move and see whether it requires more
  1885.            than one insn.  If it does, we emit those insns and
  1886.            delete INSN.  Otherwise, we an just replace the pattern 
  1887.            of INSN; we have already verified above that INSN has
  1888.            no other function that to do X.  */
  1889.  
  1890.         pat = gen_move_insn (SET_DEST (x), SET_SRC (x));
  1891.         if (GET_CODE (pat) == SEQUENCE)
  1892.           {
  1893.         emit_insn_after (pat, insn);
  1894.         PUT_CODE (insn, NOTE);
  1895.         NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
  1896.         NOTE_SOURCE_FILE (insn) = 0;
  1897.           }
  1898.         else
  1899.           PATTERN (insn) = pat;
  1900.  
  1901.         return;
  1902.       }
  1903.  
  1904.     if ((SET_DEST (x) == var
  1905.          || (GET_CODE (SET_DEST (x)) == SUBREG
  1906.          && SUBREG_REG (SET_DEST (x)) == var))
  1907.         && (GET_CODE (SET_SRC (x)) == REG
  1908.         || (GET_CODE (SET_SRC (x)) == SUBREG
  1909.             && GET_CODE (SUBREG_REG (SET_SRC (x))) == REG))
  1910.         && x == single_set (PATTERN (insn)))
  1911.       {
  1912.         rtx pat;
  1913.  
  1914.         if (GET_CODE (SET_DEST (x)) == SUBREG)
  1915.           SET_DEST (x) = fixup_memory_subreg (SET_DEST (x), insn, 0);
  1916.         else
  1917.           SET_DEST (x) = fixup_stack_1 (SET_DEST (x), insn);
  1918.  
  1919.         if (recog_memoized (insn) >= 0)
  1920.           return;
  1921.  
  1922.         pat = gen_move_insn (SET_DEST (x), SET_SRC (x));
  1923.         if (GET_CODE (pat) == SEQUENCE)
  1924.           {
  1925.         emit_insn_after (pat, insn);
  1926.         PUT_CODE (insn, NOTE);
  1927.         NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
  1928.         NOTE_SOURCE_FILE (insn) = 0;
  1929.           }
  1930.         else
  1931.           PATTERN (insn) = pat;
  1932.  
  1933.         return;
  1934.       }
  1935.  
  1936.     /* Otherwise, storing into VAR must be handled specially
  1937.        by storing into a temporary and copying that into VAR
  1938.        with a new insn after this one.  Note that this case
  1939.        will be used when storing into a promoted scalar since
  1940.        the insn will now have different modes on the input
  1941.        and output and hence will be invalid (except for the case
  1942.        of setting it to a constant, which does not need any
  1943.        change if it is valid).  We generate extra code in that case,
  1944.        but combine.c will eliminate it.  */
  1945.  
  1946.     if (dest == var)
  1947.       {
  1948.         rtx temp;
  1949.         rtx fixeddest = SET_DEST (x);
  1950.  
  1951.         /* STRICT_LOW_PART can be discarded, around a MEM.  */
  1952.         if (GET_CODE (fixeddest) == STRICT_LOW_PART)
  1953.           fixeddest = XEXP (fixeddest, 0);
  1954.         /* Convert (SUBREG (MEM)) to a MEM in a changed mode.  */
  1955.         if (GET_CODE (fixeddest) == SUBREG)
  1956.           fixeddest = fixup_memory_subreg (fixeddest, insn, 0);
  1957.         else
  1958.           fixeddest = fixup_stack_1 (fixeddest, insn);
  1959.  
  1960.         temp = gen_reg_rtx (GET_MODE (SET_SRC (x)) == VOIDmode
  1961.                 ? GET_MODE (fixeddest)
  1962.                 : GET_MODE (SET_SRC (x)));
  1963.  
  1964.         emit_insn_after (gen_move_insn (fixeddest,
  1965.                         gen_lowpart (GET_MODE (fixeddest),
  1966.                              temp)),
  1967.                  insn);
  1968.  
  1969.         SET_DEST (x) = temp;
  1970.       }
  1971.       }
  1972.     }
  1973.  
  1974.   /* Nothing special about this RTX; fix its operands.  */
  1975.  
  1976.   fmt = GET_RTX_FORMAT (code);
  1977.   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  1978.     {
  1979.       if (fmt[i] == 'e')
  1980.     fixup_var_refs_1 (var, promoted_mode, &XEXP (x, i), insn, replacements);
  1981.       if (fmt[i] == 'E')
  1982.     {
  1983.       register int j;
  1984.       for (j = 0; j < XVECLEN (x, i); j++)
  1985.         fixup_var_refs_1 (var, promoted_mode, &XVECEXP (x, i, j),
  1986.                   insn, replacements);
  1987.     }
  1988.     }
  1989. }
  1990.  
  1991. /* Given X, an rtx of the form (SUBREG:m1 (MEM:m2 addr)),
  1992.    return an rtx (MEM:m1 newaddr) which is equivalent.
  1993.    If any insns must be emitted to compute NEWADDR, put them before INSN.
  1994.  
  1995.    UNCRITICAL nonzero means accept paradoxical subregs.
  1996.    This is used for subregs found inside of ZERO_EXTRACTs and in REG_NOTES. */
  1997.  
  1998. static rtx
  1999. fixup_memory_subreg (x, insn, uncritical)
  2000.      rtx x;
  2001.      rtx insn;
  2002.      int uncritical;
  2003. {
  2004.   int offset = SUBREG_WORD (x) * UNITS_PER_WORD;
  2005.   rtx addr = XEXP (SUBREG_REG (x), 0);
  2006.   enum machine_mode mode = GET_MODE (x);
  2007.   rtx saved, result;
  2008.  
  2009.   /* Paradoxical SUBREGs are usually invalid during RTL generation.  */
  2010.   if (GET_MODE_SIZE (mode) > GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)))
  2011.       && ! uncritical)
  2012.     abort ();
  2013.  
  2014. #if BYTES_BIG_ENDIAN
  2015.   offset += (MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))))
  2016.          - MIN (UNITS_PER_WORD, GET_MODE_SIZE (mode)));
  2017. #endif
  2018.   addr = plus_constant (addr, offset);
  2019.   if (!flag_force_addr && memory_address_p (mode, addr))
  2020.     /* Shortcut if no insns need be emitted.  */
  2021.     return change_address (SUBREG_REG (x), mode, addr);
  2022.   start_sequence ();
  2023.   result = change_address (SUBREG_REG (x), mode, addr);
  2024.   emit_insn_before (gen_sequence (), insn);
  2025.   end_sequence ();
  2026.   return result;
  2027. }
  2028.  
  2029. /* Do fixup_memory_subreg on all (SUBREG (MEM ...) ...) contained in X.
  2030.    Replace subexpressions of X in place.
  2031.    If X itself is a (SUBREG (MEM ...) ...), return the replacement expression.
  2032.    Otherwise return X, with its contents possibly altered.
  2033.  
  2034.    If any insns must be emitted to compute NEWADDR, put them before INSN. 
  2035.  
  2036.    UNCRITICAL is as in fixup_memory_subreg.  */
  2037.  
  2038. static rtx
  2039. walk_fixup_memory_subreg (x, insn, uncritical)
  2040.      register rtx x;
  2041.      rtx insn;
  2042.      int uncritical;
  2043. {
  2044.   register enum rtx_code code;
  2045.   register char *fmt;
  2046.   register int i;
  2047.  
  2048.   if (x == 0)
  2049.     return 0;
  2050.  
  2051.   code = GET_CODE (x);
  2052.  
  2053.   if (code == SUBREG && GET_CODE (SUBREG_REG (x)) == MEM)
  2054.     return fixup_memory_subreg (x, insn, uncritical);
  2055.  
  2056.   /* Nothing special about this RTX; fix its operands.  */
  2057.  
  2058.   fmt = GET_RTX_FORMAT (code);
  2059.   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  2060.     {
  2061.       if (fmt[i] == 'e')
  2062.     XEXP (x, i) = walk_fixup_memory_subreg (XEXP (x, i), insn, uncritical);
  2063.       if (fmt[i] == 'E')
  2064.     {
  2065.       register int j;
  2066.       for (j = 0; j < XVECLEN (x, i); j++)
  2067.         XVECEXP (x, i, j)
  2068.           = walk_fixup_memory_subreg (XVECEXP (x, i, j), insn, uncritical);
  2069.     }
  2070.     }
  2071.   return x;
  2072. }
  2073.  
  2074. /* For each memory ref within X, if it refers to a stack slot
  2075.    with an out of range displacement, put the address in a temp register
  2076.    (emitting new insns before INSN to load these registers)
  2077.    and alter the memory ref to use that register.
  2078.    Replace each such MEM rtx with a copy, to avoid clobberage.  */
  2079.  
  2080. static rtx
  2081. fixup_stack_1 (x, insn)
  2082.      rtx x;
  2083.      rtx insn;
  2084. {
  2085.   register int i;
  2086.   register RTX_CODE code = GET_CODE (x);
  2087.   register char *fmt;
  2088.  
  2089.   if (code == MEM)
  2090.     {
  2091.       register rtx ad = XEXP (x, 0);
  2092.       /* If we have address of a stack slot but it's not valid
  2093.      (displacement is too large), compute the sum in a register.  */
  2094.       if (GET_CODE (ad) == PLUS
  2095.       && GET_CODE (XEXP (ad, 0)) == REG
  2096.       && ((REGNO (XEXP (ad, 0)) >= FIRST_VIRTUAL_REGISTER
  2097.            && REGNO (XEXP (ad, 0)) <= LAST_VIRTUAL_REGISTER)
  2098.           || XEXP (ad, 0) == current_function_internal_arg_pointer)
  2099.       && GET_CODE (XEXP (ad, 1)) == CONST_INT)
  2100.     {
  2101.       rtx temp, seq;
  2102.       if (memory_address_p (GET_MODE (x), ad))
  2103.         return x;
  2104.  
  2105.       start_sequence ();
  2106.       temp = copy_to_reg (ad);
  2107.       seq = gen_sequence ();
  2108.       end_sequence ();
  2109.       emit_insn_before (seq, insn);
  2110.       return change_address (x, VOIDmode, temp);
  2111.     }
  2112.       return x;
  2113.     }
  2114.  
  2115.   fmt = GET_RTX_FORMAT (code);
  2116.   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  2117.     {
  2118.       if (fmt[i] == 'e')
  2119.     XEXP (x, i) = fixup_stack_1 (XEXP (x, i), insn);
  2120.       if (fmt[i] == 'E')
  2121.     {
  2122.       register int j;
  2123.       for (j = 0; j < XVECLEN (x, i); j++)
  2124.         XVECEXP (x, i, j) = fixup_stack_1 (XVECEXP (x, i, j), insn);
  2125.     }
  2126.     }
  2127.   return x;
  2128. }
  2129.  
  2130. /* Optimization: a bit-field instruction whose field
  2131.    happens to be a byte or halfword in memory
  2132.    can be changed to a move instruction.
  2133.  
  2134.    We call here when INSN is an insn to examine or store into a bit-field.
  2135.    BODY is the SET-rtx to be altered.
  2136.  
  2137.    EQUIV_MEM is the table `reg_equiv_mem' if that is available; else 0.
  2138.    (Currently this is called only from function.c, and EQUIV_MEM
  2139.    is always 0.)  */
  2140.  
  2141. static void
  2142. optimize_bit_field (body, insn, equiv_mem)
  2143.      rtx body;
  2144.      rtx insn;
  2145.      rtx *equiv_mem;
  2146. {
  2147.   register rtx bitfield;
  2148.   int destflag;
  2149.   rtx seq = 0;
  2150.   enum machine_mode mode;
  2151.  
  2152.   if (GET_CODE (SET_DEST (body)) == SIGN_EXTRACT
  2153.       || GET_CODE (SET_DEST (body)) == ZERO_EXTRACT)
  2154.     bitfield = SET_DEST (body), destflag = 1;
  2155.   else
  2156.     bitfield = SET_SRC (body), destflag = 0;
  2157.  
  2158.   /* First check that the field being stored has constant size and position
  2159.      and is in fact a byte or halfword suitably aligned.  */
  2160.  
  2161.   if (GET_CODE (XEXP (bitfield, 1)) == CONST_INT
  2162.       && GET_CODE (XEXP (bitfield, 2)) == CONST_INT
  2163.       && ((mode = mode_for_size (INTVAL (XEXP (bitfield, 1)), MODE_INT, 1))
  2164.       != BLKmode)
  2165.       && INTVAL (XEXP (bitfield, 2)) % INTVAL (XEXP (bitfield, 1)) == 0)
  2166.     {
  2167.       register rtx memref = 0;
  2168.  
  2169.       /* Now check that the containing word is memory, not a register,
  2170.      and that it is safe to change the machine mode.  */
  2171.  
  2172.       if (GET_CODE (XEXP (bitfield, 0)) == MEM)
  2173.     memref = XEXP (bitfield, 0);
  2174.       else if (GET_CODE (XEXP (bitfield, 0)) == REG
  2175.            && equiv_mem != 0)
  2176.     memref = equiv_mem[REGNO (XEXP (bitfield, 0))];
  2177.       else if (GET_CODE (XEXP (bitfield, 0)) == SUBREG
  2178.            && GET_CODE (SUBREG_REG (XEXP (bitfield, 0))) == MEM)
  2179.     memref = SUBREG_REG (XEXP (bitfield, 0));
  2180.       else if (GET_CODE (XEXP (bitfield, 0)) == SUBREG
  2181.            && equiv_mem != 0
  2182.            && GET_CODE (SUBREG_REG (XEXP (bitfield, 0))) == REG)
  2183.     memref = equiv_mem[REGNO (SUBREG_REG (XEXP (bitfield, 0)))];
  2184.  
  2185.       if (memref
  2186.       && ! mode_dependent_address_p (XEXP (memref, 0))
  2187.       && ! MEM_VOLATILE_P (memref))
  2188.     {
  2189.       /* Now adjust the address, first for any subreg'ing
  2190.          that we are now getting rid of,
  2191.          and then for which byte of the word is wanted.  */
  2192.  
  2193.       register int offset = INTVAL (XEXP (bitfield, 2));
  2194.       /* Adjust OFFSET to count bits from low-address byte.  */
  2195. #if BITS_BIG_ENDIAN != BYTES_BIG_ENDIAN
  2196.       offset = (GET_MODE_BITSIZE (GET_MODE (XEXP (bitfield, 0)))
  2197.             - offset - INTVAL (XEXP (bitfield, 1)));
  2198. #endif
  2199.       /* Adjust OFFSET to count bytes from low-address byte.  */
  2200.       offset /= BITS_PER_UNIT;
  2201.       if (GET_CODE (XEXP (bitfield, 0)) == SUBREG)
  2202.         {
  2203.           offset += SUBREG_WORD (XEXP (bitfield, 0)) * UNITS_PER_WORD;
  2204. #if BYTES_BIG_ENDIAN
  2205.           offset -= (MIN (UNITS_PER_WORD,
  2206.                   GET_MODE_SIZE (GET_MODE (XEXP (bitfield, 0))))
  2207.              - MIN (UNITS_PER_WORD,
  2208.                 GET_MODE_SIZE (GET_MODE (memref))));
  2209. #endif
  2210.         }
  2211.  
  2212.       memref = change_address (memref, mode, 
  2213.                    plus_constant (XEXP (memref, 0), offset));
  2214.  
  2215.       /* Store this memory reference where
  2216.          we found the bit field reference.  */
  2217.  
  2218.       if (destflag)
  2219.         {
  2220.           validate_change (insn, &SET_DEST (body), memref, 1);
  2221.           if (! CONSTANT_ADDRESS_P (SET_SRC (body)))
  2222.         {
  2223.           rtx src = SET_SRC (body);
  2224.           while (GET_CODE (src) == SUBREG
  2225.              && SUBREG_WORD (src) == 0)
  2226.             src = SUBREG_REG (src);
  2227.           if (GET_MODE (src) != GET_MODE (memref))
  2228.             src = gen_lowpart (GET_MODE (memref), SET_SRC (body));
  2229.           validate_change (insn, &SET_SRC (body), src, 1);
  2230.         }
  2231.           else if (GET_MODE (SET_SRC (body)) != VOIDmode
  2232.                && GET_MODE (SET_SRC (body)) != GET_MODE (memref))
  2233.         /* This shouldn't happen because anything that didn't have
  2234.            one of these modes should have got converted explicitly
  2235.            and then referenced through a subreg.
  2236.            This is so because the original bit-field was
  2237.            handled by agg_mode and so its tree structure had
  2238.            the same mode that memref now has.  */
  2239.         abort ();
  2240.         }
  2241.       else
  2242.         {
  2243.           rtx dest = SET_DEST (body);
  2244.  
  2245.           while (GET_CODE (dest) == SUBREG
  2246.              && SUBREG_WORD (dest) == 0)
  2247.         dest = SUBREG_REG (dest);
  2248.  
  2249.           validate_change (insn, &SET_DEST (body), dest, 1);
  2250.  
  2251.           if (GET_MODE (dest) == GET_MODE (memref))
  2252.         validate_change (insn, &SET_SRC (body), memref, 1);
  2253.           else
  2254.         {
  2255.           /* Convert the mem ref to the destination mode.  */
  2256.           rtx newreg = gen_reg_rtx (GET_MODE (dest));
  2257.  
  2258.           start_sequence ();
  2259.           convert_move (newreg, memref,
  2260.                 GET_CODE (SET_SRC (body)) == ZERO_EXTRACT);
  2261.           seq = get_insns ();
  2262.           end_sequence ();
  2263.  
  2264.           validate_change (insn, &SET_SRC (body), newreg, 1);
  2265.         }
  2266.         }
  2267.  
  2268.       /* See if we can convert this extraction or insertion into
  2269.          a simple move insn.  We might not be able to do so if this
  2270.          was, for example, part of a PARALLEL.
  2271.  
  2272.          If we succeed, write out any needed conversions.  If we fail,
  2273.          it is hard to guess why we failed, so don't do anything
  2274.          special; just let the optimization be suppressed.  */
  2275.  
  2276.       if (apply_change_group () && seq)
  2277.         emit_insns_before (seq, insn);
  2278.     }
  2279.     }
  2280. }
  2281.  
  2282. /* These routines are responsible for converting virtual register references
  2283.    to the actual hard register references once RTL generation is complete.
  2284.  
  2285.    The following four variables are used for communication between the
  2286.    routines.  They contain the offsets of the virtual registers from their
  2287.    respective hard registers.  */
  2288.  
  2289. static int in_arg_offset;
  2290. static int var_offset;
  2291. static int dynamic_offset;
  2292. static int out_arg_offset;
  2293.  
  2294. /* In most machines, the stack pointer register is equivalent to the bottom
  2295.    of the stack.  */
  2296.  
  2297. #ifndef STACK_POINTER_OFFSET
  2298. #define STACK_POINTER_OFFSET    0
  2299. #endif
  2300.  
  2301. /* If not defined, pick an appropriate default for the offset of dynamically
  2302.    allocated memory depending on the value of ACCUMULATE_OUTGOING_ARGS,
  2303.    REG_PARM_STACK_SPACE, and OUTGOING_REG_PARM_STACK_SPACE.  */
  2304.  
  2305. #ifndef STACK_DYNAMIC_OFFSET
  2306.  
  2307. #ifdef ACCUMULATE_OUTGOING_ARGS
  2308. /* The bottom of the stack points to the actual arguments.  If
  2309.    REG_PARM_STACK_SPACE is defined, this includes the space for the register
  2310.    parameters.  However, if OUTGOING_REG_PARM_STACK space is not defined,
  2311.    stack space for register parameters is not pushed by the caller, but 
  2312.    rather part of the fixed stack areas and hence not included in
  2313.    `current_function_outgoing_args_size'.  Nevertheless, we must allow
  2314.    for it when allocating stack dynamic objects.  */
  2315.  
  2316. #if defined(REG_PARM_STACK_SPACE) && ! defined(OUTGOING_REG_PARM_STACK_SPACE)
  2317. #define STACK_DYNAMIC_OFFSET(FNDECL)    \
  2318. (current_function_outgoing_args_size    \
  2319.  + REG_PARM_STACK_SPACE (FNDECL) + (STACK_POINTER_OFFSET))
  2320.  
  2321. #else
  2322. #define STACK_DYNAMIC_OFFSET(FNDECL)    \
  2323. (current_function_outgoing_args_size + (STACK_POINTER_OFFSET))
  2324. #endif
  2325.  
  2326. #else
  2327. #define STACK_DYNAMIC_OFFSET(FNDECL) STACK_POINTER_OFFSET
  2328. #endif
  2329. #endif
  2330.  
  2331. /* Pass through the INSNS of function FNDECL and convert virtual register
  2332.    references to hard register references.  */
  2333.  
  2334. void
  2335. instantiate_virtual_regs (fndecl, insns)
  2336.      tree fndecl;
  2337.      rtx insns;
  2338. {
  2339.   rtx insn;
  2340.  
  2341.   /* Compute the offsets to use for this function.  */
  2342.   in_arg_offset = FIRST_PARM_OFFSET (fndecl);
  2343.   var_offset = STARTING_FRAME_OFFSET;
  2344.   dynamic_offset = STACK_DYNAMIC_OFFSET (fndecl);
  2345.   out_arg_offset = STACK_POINTER_OFFSET;
  2346.  
  2347.   /* Scan all variables and parameters of this function.  For each that is
  2348.      in memory, instantiate all virtual registers if the result is a valid
  2349.      address.  If not, we do it later.  That will handle most uses of virtual
  2350.      regs on many machines.  */
  2351.   instantiate_decls (fndecl, 1);
  2352.  
  2353.   /* Initialize recognition, indicating that volatile is OK.  */
  2354.   init_recog ();
  2355.  
  2356.   /* Scan through all the insns, instantiating every virtual register still
  2357.      present.  */
  2358.   for (insn = insns; insn; insn = NEXT_INSN (insn))
  2359.     if (GET_CODE (insn) == INSN || GET_CODE (insn) == JUMP_INSN
  2360.     || GET_CODE (insn) == CALL_INSN)
  2361.       {
  2362.     instantiate_virtual_regs_1 (&PATTERN (insn), insn, 1);
  2363.     instantiate_virtual_regs_1 (®_NOTES (insn), NULL_RTX, 0);
  2364.       }
  2365.  
  2366.   /* Now instantiate the remaining register equivalences for debugging info.
  2367.      These will not be valid addresses.  */
  2368.   instantiate_decls (fndecl, 0);
  2369.  
  2370.   /* Indicate that, from now on, assign_stack_local should use
  2371.      frame_pointer_rtx.  */
  2372.   virtuals_instantiated = 1;
  2373. }
  2374.  
  2375. /* Scan all decls in FNDECL (both variables and parameters) and instantiate
  2376.    all virtual registers in their DECL_RTL's.
  2377.  
  2378.    If VALID_ONLY, do this only if the resulting address is still valid.
  2379.    Otherwise, always do it.  */
  2380.  
  2381. static void
  2382. instantiate_decls (fndecl, valid_only)
  2383.      tree fndecl;
  2384.      int valid_only;
  2385. {
  2386.   tree decl;
  2387.  
  2388.   if (DECL_INLINE (fndecl))
  2389.     /* When compiling an inline function, the obstack used for
  2390.        rtl allocation is the maybepermanent_obstack.  Calling
  2391.        `resume_temporary_allocation' switches us back to that
  2392.        obstack while we process this function's parameters.  */
  2393.     resume_temporary_allocation ();
  2394.  
  2395.   /* Process all parameters of the function.  */
  2396.   for (decl = DECL_ARGUMENTS (fndecl); decl; decl = TREE_CHAIN (decl))
  2397.     {
  2398.       instantiate_decl (DECL_RTL (decl), int_size_in_bytes (TREE_TYPE (decl)),
  2399.             valid_only);    
  2400.       instantiate_decl (DECL_INCOMING_RTL (decl),
  2401.             int_size_in_bytes (TREE_TYPE (decl)), valid_only);
  2402.     }
  2403.  
  2404.   /* Now process all variables defined in the function or its subblocks. */
  2405.   instantiate_decls_1 (DECL_INITIAL (fndecl), valid_only);
  2406.  
  2407.   if (DECL_INLINE (fndecl))
  2408.     {
  2409.       /* Save all rtl allocated for this function by raising the
  2410.      high-water mark on the maybepermanent_obstack.  */
  2411.       preserve_data ();
  2412.       /* All further rtl allocation is now done in the current_obstack.  */
  2413.       rtl_in_current_obstack ();
  2414.     }
  2415. }
  2416.  
  2417. /* Subroutine of instantiate_decls: Process all decls in the given
  2418.    BLOCK node and all its subblocks.  */
  2419.  
  2420. static void
  2421. instantiate_decls_1 (let, valid_only)
  2422.      tree let;
  2423.      int valid_only;
  2424. {
  2425.   tree t;
  2426.  
  2427.   for (t = BLOCK_VARS (let); t; t = TREE_CHAIN (t))
  2428.     instantiate_decl (DECL_RTL (t), int_size_in_bytes (TREE_TYPE (t)),
  2429.               valid_only);
  2430.  
  2431.   /* Process all subblocks.  */
  2432.   for (t = BLOCK_SUBBLOCKS (let); t; t = TREE_CHAIN (t))
  2433.     instantiate_decls_1 (t, valid_only);
  2434. }
  2435.  
  2436. /* Subroutine of the preceding procedures: Given RTL representing a
  2437.    decl and the size of the object, do any instantiation required.
  2438.  
  2439.    If VALID_ONLY is non-zero, it means that the RTL should only be
  2440.    changed if the new address is valid.  */
  2441.  
  2442. static void
  2443. instantiate_decl (x, size, valid_only)
  2444.      rtx x;
  2445.      int size;
  2446.      int valid_only;
  2447. {
  2448.   enum machine_mode mode;
  2449.   rtx addr;
  2450.  
  2451.   /* If this is not a MEM, no need to do anything.  Similarly if the
  2452.      address is a constant or a register that is not a virtual register.  */
  2453.  
  2454.   if (x == 0 || GET_CODE (x) != MEM)
  2455.     return;
  2456.  
  2457.   addr = XEXP (x, 0);
  2458.   if (CONSTANT_P (addr)
  2459.       || (GET_CODE (addr) == REG
  2460.       && (REGNO (addr) < FIRST_VIRTUAL_REGISTER
  2461.           || REGNO (addr) > LAST_VIRTUAL_REGISTER)))
  2462.     return;
  2463.  
  2464.   /* If we should only do this if the address is valid, copy the address.
  2465.      We need to do this so we can undo any changes that might make the
  2466.      address invalid.  This copy is unfortunate, but probably can't be
  2467.      avoided.  */
  2468.  
  2469.   if (valid_only)
  2470.     addr = copy_rtx (addr);
  2471.  
  2472.   instantiate_virtual_regs_1 (&addr, NULL_RTX, 0);
  2473.  
  2474.   if (! valid_only)
  2475.     return;
  2476.  
  2477.   /* Now verify that the resulting address is valid for every integer or
  2478.      floating-point mode up to and including SIZE bytes long.  We do this
  2479.      since the object might be accessed in any mode and frame addresses
  2480.      are shared.  */
  2481.  
  2482.   for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT);
  2483.        mode != VOIDmode && GET_MODE_SIZE (mode) <= size;
  2484.        mode = GET_MODE_WIDER_MODE (mode))
  2485.     if (! memory_address_p (mode, addr))
  2486.       return;
  2487.  
  2488.   for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT);
  2489.        mode != VOIDmode && GET_MODE_SIZE (mode) <= size;
  2490.        mode = GET_MODE_WIDER_MODE (mode))
  2491.     if (! memory_address_p (mode, addr))
  2492.       return;
  2493.  
  2494.   /* Otherwise, put back the address, now that we have updated it and we
  2495.      know it is valid.  */
  2496.  
  2497.   XEXP (x, 0) = addr;
  2498. }
  2499.  
  2500. /* Given a pointer to a piece of rtx and an optional pointer to the
  2501.    containing object, instantiate any virtual registers present in it.
  2502.  
  2503.    If EXTRA_INSNS, we always do the replacement and generate
  2504.    any extra insns before OBJECT.  If it zero, we do nothing if replacement
  2505.    is not valid.
  2506.  
  2507.    Return 1 if we either had nothing to do or if we were able to do the
  2508.    needed replacement.  Return 0 otherwise; we only return zero if 
  2509.    EXTRA_INSNS is zero.
  2510.  
  2511.    We first try some simple transformations to avoid the creation of extra
  2512.    pseudos.  */
  2513.  
  2514. static int
  2515. instantiate_virtual_regs_1 (loc, object, extra_insns)
  2516.      rtx *loc;
  2517.      rtx object;
  2518.      int extra_insns;
  2519. {
  2520.   rtx x;
  2521.   RTX_CODE code;
  2522.   rtx new = 0;
  2523.   int offset;
  2524.   rtx temp;
  2525.   rtx seq;
  2526.   int i, j;
  2527.   char *fmt;
  2528.  
  2529.   /* Re-start here to avoid recursion in common cases.  */
  2530.  restart:
  2531.  
  2532.   x = *loc;
  2533.   if (x == 0)
  2534.     return 1;
  2535.  
  2536.   code = GET_CODE (x);
  2537.  
  2538.   /* Check for some special cases.  */
  2539.   switch (code)
  2540.     {
  2541.     case CONST_INT:
  2542.     case CONST_DOUBLE:
  2543.     case CONST:
  2544.     case SYMBOL_REF:
  2545.     case CODE_LABEL:
  2546.     case PC:
  2547.     case CC0:
  2548.     case ASM_INPUT:
  2549.     case ADDR_VEC:
  2550.     case ADDR_DIFF_VEC:
  2551.     case RETURN:
  2552.       return 1;
  2553.  
  2554.     case SET:
  2555.       /* We are allowed to set the virtual registers.  This means that
  2556.      that the actual register should receive the source minus the
  2557.      appropriate offset.  This is used, for example, in the handling
  2558.      of non-local gotos.  */
  2559.       if (SET_DEST (x) == virtual_incoming_args_rtx)
  2560.     new = arg_pointer_rtx, offset = - in_arg_offset;
  2561.       else if (SET_DEST (x) == virtual_stack_vars_rtx)
  2562.     new = frame_pointer_rtx, offset = - var_offset;
  2563.       else if (SET_DEST (x) == virtual_stack_dynamic_rtx)
  2564.     new = stack_pointer_rtx, offset = - dynamic_offset;
  2565.       else if (SET_DEST (x) == virtual_outgoing_args_rtx)
  2566.     new = stack_pointer_rtx, offset = - out_arg_offset;
  2567.  
  2568.       if (new)
  2569.     {
  2570.       /* The only valid sources here are PLUS or REG.  Just do
  2571.          the simplest possible thing to handle them.  */
  2572.       if (GET_CODE (SET_SRC (x)) != REG
  2573.           && GET_CODE (SET_SRC (x)) != PLUS)
  2574.         abort ();
  2575.  
  2576.       start_sequence ();
  2577.       if (GET_CODE (SET_SRC (x)) != REG)
  2578.         temp = force_operand (SET_SRC (x), NULL_RTX);
  2579.       else
  2580.         temp = SET_SRC (x);
  2581.       temp = force_operand (plus_constant (temp, offset), NULL_RTX);
  2582.       seq = get_insns ();
  2583.       end_sequence ();
  2584.  
  2585.       emit_insns_before (seq, object);
  2586.       SET_DEST (x) = new;
  2587.  
  2588.       if (!validate_change (object, &SET_SRC (x), temp, 0)
  2589.           || ! extra_insns)
  2590.         abort ();
  2591.  
  2592.       return 1;
  2593.     }
  2594.  
  2595.       instantiate_virtual_regs_1 (&SET_DEST (x), object, extra_insns);
  2596.       loc = &SET_SRC (x);
  2597.       goto restart;
  2598.  
  2599.     case PLUS:
  2600.       /* Handle special case of virtual register plus constant.  */
  2601.       if (CONSTANT_P (XEXP (x, 1)))
  2602.     {
  2603.       rtx old;
  2604.  
  2605.       /* Check for (plus (plus VIRT foo) (const_int)) first.  */
  2606.       if (GET_CODE (XEXP (x, 0)) == PLUS)
  2607.         {
  2608.           rtx inner = XEXP (XEXP (x, 0), 0);
  2609.  
  2610.           if (inner == virtual_incoming_args_rtx)
  2611.         new = arg_pointer_rtx, offset = in_arg_offset;
  2612.           else if (inner == virtual_stack_vars_rtx)
  2613.         new = frame_pointer_rtx, offset = var_offset;
  2614.           else if (inner == virtual_stack_dynamic_rtx)
  2615.         new = stack_pointer_rtx, offset = dynamic_offset;
  2616.           else if (inner == virtual_outgoing_args_rtx)
  2617.         new = stack_pointer_rtx, offset = out_arg_offset;
  2618.           else
  2619.         {
  2620.           loc = &XEXP (x, 0);
  2621.           goto restart;
  2622.         }
  2623.  
  2624.           instantiate_virtual_regs_1 (&XEXP (XEXP (x, 0), 1), object,
  2625.                       extra_insns);
  2626.           new = gen_rtx (PLUS, Pmode, new, XEXP (XEXP (x, 0), 1));
  2627.         }
  2628.  
  2629.       else if (XEXP (x, 0) == virtual_incoming_args_rtx)
  2630.         new = arg_pointer_rtx, offset = in_arg_offset;
  2631.       else if (XEXP (x, 0) == virtual_stack_vars_rtx)
  2632.         new = frame_pointer_rtx, offset = var_offset;
  2633.       else if (XEXP (x, 0) == virtual_stack_dynamic_rtx)
  2634.         new = stack_pointer_rtx, offset = dynamic_offset;
  2635.       else if (XEXP (x, 0) == virtual_outgoing_args_rtx)
  2636.         new = stack_pointer_rtx, offset = out_arg_offset;
  2637.       else
  2638.         {
  2639.           /* We know the second operand is a constant.  Unless the
  2640.          first operand is a REG (which has been already checked),
  2641.          it needs to be checked.  */
  2642.           if (GET_CODE (XEXP (x, 0)) != REG)
  2643.         {
  2644.           loc = &XEXP (x, 0);
  2645.           goto restart;
  2646.         }
  2647.           return 1;
  2648.         }
  2649.  
  2650.       old = XEXP (x, 0);
  2651.       XEXP (x, 0) = new;
  2652.       new = plus_constant (XEXP (x, 1), offset);
  2653.  
  2654.       /* If the new constant is zero, try to replace the sum with its
  2655.          first operand.  */
  2656.       if (new == const0_rtx
  2657.           && validate_change (object, loc, XEXP (x, 0), 0))
  2658.         return 1;
  2659.  
  2660.       /* Next try to replace constant with new one.  */
  2661.       if (!validate_change (object, &XEXP (x, 1), new, 0))
  2662.         {
  2663.           if (! extra_insns)
  2664.         {
  2665.           XEXP (x, 0) = old;
  2666.           return 0;
  2667.         }
  2668.  
  2669.           /* Otherwise copy the new constant into a register and replace
  2670.          constant with that register.  */
  2671.           temp = gen_reg_rtx (Pmode);
  2672.           if (validate_change (object, &XEXP (x, 1), temp, 0))
  2673.         emit_insn_before (gen_move_insn (temp, new), object);
  2674.           else
  2675.         {
  2676.           /* If that didn't work, replace this expression with a
  2677.              register containing the sum.  */
  2678.  
  2679.           new = gen_rtx (PLUS, Pmode, XEXP (x, 0), new);
  2680.           XEXP (x, 0) = old;
  2681.  
  2682.           start_sequence ();
  2683.           temp = force_operand (new, NULL_RTX);
  2684.           seq = get_insns ();
  2685.           end_sequence ();
  2686.  
  2687.           emit_insns_before (seq, object);
  2688.           if (! validate_change (object, loc, temp, 0)
  2689.               && ! validate_replace_rtx (x, temp, object))
  2690.             abort ();
  2691.         }
  2692.         }
  2693.  
  2694.       return 1;
  2695.     }
  2696.  
  2697.       /* Fall through to generic two-operand expression case.  */
  2698.     case EXPR_LIST:
  2699.     case CALL:
  2700.     case COMPARE:
  2701.     case MINUS:
  2702.     case MULT:
  2703.     case DIV:      case UDIV:
  2704.     case MOD:      case UMOD:
  2705.     case AND:      case IOR:      case XOR:
  2706.     case ROTATERT: case ROTATE:
  2707.     case ASHIFTRT: case LSHIFTRT: case ASHIFT:
  2708.     case NE:       case EQ:
  2709.     case GE:       case GT:       case GEU:    case GTU:
  2710.     case LE:       case LT:       case LEU:    case LTU:
  2711.       if (XEXP (x, 1) && ! CONSTANT_P (XEXP (x, 1)))
  2712.     instantiate_virtual_regs_1 (&XEXP (x, 1), object, extra_insns);
  2713.       loc = &XEXP (x, 0);
  2714.       goto restart;
  2715.  
  2716.     case MEM:
  2717.       /* Most cases of MEM that convert to valid addresses have already been
  2718.      handled by our scan of regno_reg_rtx.  The only special handling we
  2719.      need here is to make a copy of the rtx to ensure it isn't being
  2720.      shared if we have to change it to a pseudo. 
  2721.  
  2722.      If the rtx is a simple reference to an address via a virtual register,
  2723.      it can potentially be shared.  In such cases, first try to make it
  2724.      a valid address, which can also be shared.  Otherwise, copy it and
  2725.      proceed normally. 
  2726.  
  2727.      First check for common cases that need no processing.  These are
  2728.      usually due to instantiation already being done on a previous instance
  2729.      of a shared rtx.  */
  2730.  
  2731.       temp = XEXP (x, 0);
  2732.       if (CONSTANT_ADDRESS_P (temp)
  2733. #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
  2734.       || temp == arg_pointer_rtx
  2735. #endif
  2736. #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
  2737.       || temp == hard_frame_pointer_rtx
  2738. #endif
  2739.       || temp == frame_pointer_rtx)
  2740.     return 1;
  2741.  
  2742.       if (GET_CODE (temp) == PLUS
  2743.       && CONSTANT_ADDRESS_P (XEXP (temp, 1))
  2744.       && (XEXP (temp, 0) == frame_pointer_rtx
  2745. #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
  2746.           || XEXP (temp, 0) == hard_frame_pointer_rtx
  2747. #endif
  2748. #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
  2749.           || XEXP (temp, 0) == arg_pointer_rtx
  2750. #endif
  2751.           ))
  2752.     return 1;
  2753.  
  2754.       if (temp == virtual_stack_vars_rtx
  2755.       || temp == virtual_incoming_args_rtx
  2756.       || (GET_CODE (temp) == PLUS
  2757.           && CONSTANT_ADDRESS_P (XEXP (temp, 1))
  2758.           && (XEXP (temp, 0) == virtual_stack_vars_rtx
  2759.           || XEXP (temp, 0) == virtual_incoming_args_rtx)))
  2760.     {
  2761.       /* This MEM may be shared.  If the substitution can be done without
  2762.          the need to generate new pseudos, we want to do it in place
  2763.          so all copies of the shared rtx benefit.  The call below will
  2764.          only make substitutions if the resulting address is still
  2765.          valid.
  2766.  
  2767.          Note that we cannot pass X as the object in the recursive call
  2768.          since the insn being processed may not allow all valid
  2769.          addresses.  However, if we were not passed on object, we can
  2770.          only modify X without copying it if X will have a valid
  2771.          address.
  2772.  
  2773.          ??? Also note that this can still lose if OBJECT is an insn that
  2774.          has less restrictions on an address that some other insn.
  2775.          In that case, we will modify the shared address.  This case
  2776.          doesn't seem very likely, though.  */
  2777.  
  2778.       if (instantiate_virtual_regs_1 (&XEXP (x, 0),
  2779.                       object ? object : x, 0))
  2780.         return 1;
  2781.  
  2782.       /* Otherwise make a copy and process that copy.  We copy the entire
  2783.          RTL expression since it might be a PLUS which could also be
  2784.          shared.  */
  2785.       *loc = x = copy_rtx (x);
  2786.     }
  2787.  
  2788.       /* Fall through to generic unary operation case.  */
  2789.     case USE:
  2790.     case CLOBBER:
  2791.     case SUBREG:
  2792.     case STRICT_LOW_PART:
  2793.     case NEG:          case NOT:
  2794.     case PRE_DEC:      case PRE_INC:      case POST_DEC:    case POST_INC:
  2795.     case SIGN_EXTEND:  case ZERO_EXTEND:
  2796.     case TRUNCATE:     case FLOAT_EXTEND: case FLOAT_TRUNCATE:
  2797.     case FLOAT:        case FIX:
  2798.     case UNSIGNED_FIX: case UNSIGNED_FLOAT:
  2799.     case ABS:
  2800.     case SQRT:
  2801.     case FFS:
  2802.       /* These case either have just one operand or we know that we need not
  2803.      check the rest of the operands.  */
  2804.       loc = &XEXP (x, 0);
  2805.       goto restart;
  2806.  
  2807.     case REG:
  2808.       /* Try to replace with a PLUS.  If that doesn't work, compute the sum
  2809.      in front of this insn and substitute the temporary.  */
  2810.       if (x == virtual_incoming_args_rtx)
  2811.     new = arg_pointer_rtx, offset = in_arg_offset;
  2812.       else if (x == virtual_stack_vars_rtx)
  2813.     new = frame_pointer_rtx, offset = var_offset;
  2814.       else if (x == virtual_stack_dynamic_rtx)
  2815.     new = stack_pointer_rtx, offset = dynamic_offset;
  2816.       else if (x == virtual_outgoing_args_rtx)
  2817.     new = stack_pointer_rtx, offset = out_arg_offset;
  2818.  
  2819.       if (new)
  2820.     {
  2821.       temp = plus_constant (new, offset);
  2822.       if (!validate_change (object, loc, temp, 0))
  2823.         {
  2824.           if (! extra_insns)
  2825.         return 0;
  2826.  
  2827.           start_sequence ();
  2828.           temp = force_operand (temp, NULL_RTX);
  2829.           seq = get_insns ();
  2830.           end_sequence ();
  2831.  
  2832.           emit_insns_before (seq, object);
  2833.           if (! validate_change (object, loc, temp, 0)
  2834.           && ! validate_replace_rtx (x, temp, object))
  2835.         abort ();
  2836.         }
  2837.     }
  2838.  
  2839.       return 1;
  2840.     }
  2841.  
  2842.   /* Scan all subexpressions.  */
  2843.   fmt = GET_RTX_FORMAT (code);
  2844.   for (i = 0; i < GET_RTX_LENGTH (code); i++, fmt++)
  2845.     if (*fmt == 'e')
  2846.       {
  2847.     if (!instantiate_virtual_regs_1 (&XEXP (x, i), object, extra_insns))
  2848.       return 0;
  2849.       }
  2850.     else if (*fmt == 'E')
  2851.       for (j = 0; j < XVECLEN (x, i); j++)
  2852.     if (! instantiate_virtual_regs_1 (&XVECEXP (x, i, j), object,
  2853.                       extra_insns))
  2854.       return 0;
  2855.  
  2856.   return 1;
  2857. }
  2858.  
  2859. /* Optimization: assuming this function does not receive nonlocal gotos,
  2860.    delete the handlers for such, as well as the insns to establish
  2861.    and disestablish them.  */
  2862.  
  2863. static void
  2864. delete_handlers ()
  2865. {
  2866.   rtx insn;
  2867.   for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
  2868.     {
  2869.       /* Delete the handler by turning off the flag that would
  2870.      prevent jump_optimize from deleting it.
  2871.      Also permit deletion of the nonlocal labels themselves
  2872.      if nothing local refers to them.  */
  2873.       if (GET_CODE (insn) == CODE_LABEL)
  2874.     LABEL_PRESERVE_P (insn) = 0;
  2875.       if (GET_CODE (insn) == INSN
  2876.       && ((nonlocal_goto_handler_slot != 0
  2877.            && reg_mentioned_p (nonlocal_goto_handler_slot, PATTERN (insn)))
  2878.           || (nonlocal_goto_stack_level != 0
  2879.           && reg_mentioned_p (nonlocal_goto_stack_level,
  2880.                       PATTERN (insn)))))
  2881.     delete_insn (insn);
  2882.     }
  2883. }
  2884.  
  2885. /* Return a list (chain of EXPR_LIST nodes) for the nonlocal labels
  2886.    of the current function.  */
  2887.  
  2888. rtx
  2889. nonlocal_label_rtx_list ()
  2890. {
  2891.   tree t;
  2892.   rtx x = 0;
  2893.  
  2894.   for (t = nonlocal_labels; t; t = TREE_CHAIN (t))
  2895.     x = gen_rtx (EXPR_LIST, VOIDmode, label_rtx (TREE_VALUE (t)), x);
  2896.  
  2897.   return x;
  2898. }
  2899.  
  2900. /* Output a USE for any register use in RTL.
  2901.    This is used with -noreg to mark the extent of lifespan
  2902.    of any registers used in a user-visible variable's DECL_RTL.  */
  2903.  
  2904. void
  2905. use_variable (rtl)
  2906.      rtx rtl;
  2907. {
  2908.   if (GET_CODE (rtl) == REG)
  2909.     /* This is a register variable.  */
  2910.     emit_insn (gen_rtx (USE, VOIDmode, rtl));
  2911.   else if (GET_CODE (rtl) == MEM
  2912.        && GET_CODE (XEXP (rtl, 0)) == REG
  2913.        && (REGNO (XEXP (rtl, 0)) < FIRST_VIRTUAL_REGISTER
  2914.            || REGNO (XEXP (rtl, 0)) > LAST_VIRTUAL_REGISTER)
  2915.        && XEXP (rtl, 0) != current_function_internal_arg_pointer)
  2916.     /* This is a variable-sized structure.  */
  2917.     emit_insn (gen_rtx (USE, VOIDmode, XEXP (rtl, 0)));
  2918. }
  2919.  
  2920. /* Like use_variable except that it outputs the USEs after INSN
  2921.    instead of at the end of the insn-chain.  */
  2922.  
  2923. void
  2924. use_variable_after (rtl, insn)
  2925.      rtx rtl, insn;
  2926. {
  2927.   if (GET_CODE (rtl) == REG)
  2928.     /* This is a register variable.  */
  2929.     emit_insn_after (gen_rtx (USE, VOIDmode, rtl), insn);
  2930.   else if (GET_CODE (rtl) == MEM
  2931.        && GET_CODE (XEXP (rtl, 0)) == REG
  2932.        && (REGNO (XEXP (rtl, 0)) < FIRST_VIRTUAL_REGISTER
  2933.            || REGNO (XEXP (rtl, 0)) > LAST_VIRTUAL_REGISTER)
  2934.        && XEXP (rtl, 0) != current_function_internal_arg_pointer)
  2935.     /* This is a variable-sized structure.  */
  2936.     emit_insn_after (gen_rtx (USE, VOIDmode, XEXP (rtl, 0)), insn);
  2937. }
  2938.  
  2939. int
  2940. max_parm_reg_num ()
  2941. {
  2942.   return max_parm_reg;
  2943. }
  2944.  
  2945. /* Return the first insn following those generated by `assign_parms'.  */
  2946.  
  2947. rtx
  2948. get_first_nonparm_insn ()
  2949. {
  2950.   if (last_parm_insn)
  2951.     return NEXT_INSN (last_parm_insn);
  2952.   return get_insns ();
  2953. }
  2954.  
  2955. /* Return the first NOTE_INSN_BLOCK_BEG note in the function.
  2956.    Crash if there is none.  */
  2957.  
  2958. rtx
  2959. get_first_block_beg ()
  2960. {
  2961.   register rtx searcher;
  2962.   register rtx insn = get_first_nonparm_insn ();
  2963.  
  2964.   for (searcher = insn; searcher; searcher = NEXT_INSN (searcher))
  2965.     if (GET_CODE (searcher) == NOTE
  2966.     && NOTE_LINE_NUMBER (searcher) == NOTE_INSN_BLOCK_BEG)
  2967.       return searcher;
  2968.  
  2969.   abort ();    /* Invalid call to this function.  (See comments above.)  */
  2970.   return NULL_RTX;
  2971. }
  2972.  
  2973. /* Return 1 if EXP is an aggregate type (or a value with aggregate type).
  2974.    This means a type for which function calls must pass an address to the
  2975.    function or get an address back from the function.
  2976.    EXP may be a type node or an expression (whose type is tested).  */
  2977.  
  2978. int
  2979. aggregate_value_p (exp)
  2980.      tree exp;
  2981. {
  2982.   int i, regno, nregs;
  2983.   rtx reg;
  2984.   tree type;
  2985.   if (TREE_CODE_CLASS (TREE_CODE (exp)) == 't')
  2986.     type = exp;
  2987.   else
  2988.     type = TREE_TYPE (exp);
  2989.  
  2990.   if (RETURN_IN_MEMORY (type))
  2991.     return 1;
  2992.   if (flag_pcc_struct_return && AGGREGATE_TYPE_P (type))
  2993.     return 1;
  2994.   /* Make sure we have suitable call-clobbered regs to return
  2995.      the value in; if not, we must return it in memory.  */
  2996.   reg = hard_function_value (type, 0);
  2997.   regno = REGNO (reg);
  2998.   nregs = HARD_REGNO_NREGS (regno, TYPE_MODE (type));
  2999.   for (i = 0; i < nregs; i++)
  3000.     if (! call_used_regs[regno + i])
  3001.       return 1;
  3002.   return 0;
  3003. }
  3004.  
  3005. /* Assign RTL expressions to the function's parameters.
  3006.    This may involve copying them into registers and using
  3007.    those registers as the RTL for them.
  3008.  
  3009.    If SECOND_TIME is non-zero it means that this function is being
  3010.    called a second time.  This is done by integrate.c when a function's
  3011.    compilation is deferred.  We need to come back here in case the
  3012.    FUNCTION_ARG macro computes items needed for the rest of the compilation
  3013.    (such as changing which registers are fixed or caller-saved).  But suppress
  3014.    writing any insns or setting DECL_RTL of anything in this case.  */
  3015.  
  3016. void
  3017. assign_parms (fndecl, second_time)
  3018.      tree fndecl;
  3019.      int second_time;
  3020. {
  3021.   register tree parm;
  3022.   register rtx entry_parm = 0;
  3023.   register rtx stack_parm = 0;
  3024.   CUMULATIVE_ARGS args_so_far;
  3025.   enum machine_mode promoted_mode, passed_mode, nominal_mode;
  3026.   int unsignedp;
  3027.   /* Total space needed so far for args on the stack,
  3028.      given as a constant and a tree-expression.  */
  3029.   struct args_size stack_args_size;
  3030.   tree fntype = TREE_TYPE (fndecl);
  3031.   tree fnargs = DECL_ARGUMENTS (fndecl);
  3032.   /* This is used for the arg pointer when referring to stack args.  */
  3033.   rtx internal_arg_pointer;
  3034.   /* This is a dummy PARM_DECL that we used for the function result if 
  3035.      the function returns a structure.  */
  3036.   tree function_result_decl = 0;
  3037.   int nparmregs = list_length (fnargs) + LAST_VIRTUAL_REGISTER + 1;
  3038.   int varargs_setup = 0;
  3039.   rtx conversion_insns = 0;
  3040.   /* FUNCTION_ARG may look at this variable.  Since this is not
  3041.      expanding a call it will always be zero in this function.  */
  3042.   int current_call_is_indirect = 0;
  3043.  
  3044.   /* Nonzero if the last arg is named `__builtin_va_alist',
  3045.      which is used on some machines for old-fashioned non-ANSI varargs.h;
  3046.      this should be stuck onto the stack as if it had arrived there.  */
  3047.   int hide_last_arg
  3048.     = (current_function_varargs
  3049.        && fnargs
  3050.        && (parm = tree_last (fnargs)) != 0
  3051.        && DECL_NAME (parm)
  3052.        && (! strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
  3053.              "__builtin_va_alist")));
  3054.  
  3055.   /* Nonzero if function takes extra anonymous args.
  3056.      This means the last named arg must be on the stack
  3057.      right before the anonymous ones. */
  3058.   int stdarg
  3059.     = (TYPE_ARG_TYPES (fntype) != 0
  3060.        && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
  3061.        != void_type_node));
  3062.  
  3063.   /* If the reg that the virtual arg pointer will be translated into is
  3064.      not a fixed reg or is the stack pointer, make a copy of the virtual
  3065.      arg pointer, and address parms via the copy.  The frame pointer is
  3066.      considered fixed even though it is not marked as such.
  3067.  
  3068.      The second time through, simply use ap to avoid generating rtx.  */
  3069.  
  3070.   if ((ARG_POINTER_REGNUM == STACK_POINTER_REGNUM
  3071.        || ! (fixed_regs[ARG_POINTER_REGNUM]
  3072.          || ARG_POINTER_REGNUM == FRAME_POINTER_REGNUM))
  3073.       && ! second_time)
  3074.     internal_arg_pointer = copy_to_reg (virtual_incoming_args_rtx);
  3075.   else
  3076.     internal_arg_pointer = virtual_incoming_args_rtx;
  3077.   current_function_internal_arg_pointer = internal_arg_pointer;
  3078.  
  3079.   stack_args_size.constant = 0;
  3080.   stack_args_size.var = 0;
  3081.  
  3082.   /* If struct value address is treated as the first argument, make it so.  */
  3083.   if (aggregate_value_p (DECL_RESULT (fndecl))
  3084.       && ! current_function_returns_pcc_struct
  3085.       && struct_value_incoming_rtx == 0)
  3086.     {
  3087.       tree type = build_pointer_type (fntype);
  3088.  
  3089.       function_result_decl = build_decl (PARM_DECL, NULL_TREE, type);
  3090.  
  3091.       DECL_ARG_TYPE (function_result_decl) = type;
  3092.       TREE_CHAIN (function_result_decl) = fnargs;
  3093.       fnargs = function_result_decl;
  3094.     }
  3095.                    
  3096.   parm_reg_stack_loc = (rtx *) oballoc (nparmregs * sizeof (rtx));
  3097.   bzero ((char *) parm_reg_stack_loc, nparmregs * sizeof (rtx));
  3098.  
  3099. #ifdef INIT_CUMULATIVE_INCOMING_ARGS
  3100.   INIT_CUMULATIVE_INCOMING_ARGS (args_so_far, fntype, NULL_RTX);
  3101. #else
  3102.   INIT_CUMULATIVE_ARGS (args_so_far, fntype, NULL_RTX);
  3103. #endif
  3104.  
  3105.   /* We haven't yet found an argument that we must push and pretend the
  3106.      caller did.  */
  3107.   current_function_pretend_args_size = 0;
  3108.  
  3109.   for (parm = fnargs; parm; parm = TREE_CHAIN (parm))
  3110.     {
  3111.       int aggregate = AGGREGATE_TYPE_P (TREE_TYPE (parm));
  3112.       struct args_size stack_offset;
  3113.       struct args_size arg_size;
  3114.       int passed_pointer = 0;
  3115.       tree passed_type = DECL_ARG_TYPE (parm);
  3116.  
  3117.       /* Set LAST_NAMED if this is last named arg before some
  3118.      anonymous args.  We treat it as if it were anonymous too.  */
  3119.       int last_named = ((TREE_CHAIN (parm) == 0
  3120.              || DECL_NAME (TREE_CHAIN (parm)) == 0)
  3121.             && (stdarg || current_function_varargs));
  3122.  
  3123.       if (TREE_TYPE (parm) == error_mark_node
  3124.       /* This can happen after weird syntax errors
  3125.          or if an enum type is defined among the parms.  */
  3126.       || TREE_CODE (parm) != PARM_DECL
  3127.       || passed_type == NULL)
  3128.     {
  3129.       DECL_INCOMING_RTL (parm) = DECL_RTL (parm) = gen_rtx (MEM, BLKmode,
  3130.                                 const0_rtx);
  3131.       TREE_USED (parm) = 1;
  3132.       continue;
  3133.     }
  3134.  
  3135.       /* For varargs.h function, save info about regs and stack space
  3136.      used by the individual args, not including the va_alist arg.  */
  3137.       if (hide_last_arg && last_named)
  3138.     current_function_args_info = args_so_far;
  3139.  
  3140.       /* Find mode of arg as it is passed, and mode of arg
  3141.      as it should be during execution of this function.  */
  3142.       passed_mode = TYPE_MODE (passed_type);
  3143.       nominal_mode = TYPE_MODE (TREE_TYPE (parm));
  3144.  
  3145.       /* If the parm's mode is VOID, its value doesn't matter,
  3146.      and avoid the usual things like emit_move_insn that could crash.  */
  3147.       if (nominal_mode == VOIDmode)
  3148.     {
  3149.       DECL_INCOMING_RTL (parm) = DECL_RTL (parm) = const0_rtx;
  3150.       continue;
  3151.     }
  3152.  
  3153.       /* See if this arg was passed by invisible reference.  It is if
  3154.      it is an object whose size depends on the contents of the
  3155.      object itself or if the machine requires these objects be passed
  3156.      that way.  */
  3157.  
  3158.       if ((TREE_CODE (TYPE_SIZE (passed_type)) != INTEGER_CST
  3159.        && contains_placeholder_p (TYPE_SIZE (passed_type)))
  3160.       || TYPE_NEEDS_CONSTRUCTING (passed_type)
  3161. #ifdef FUNCTION_ARG_PASS_BY_REFERENCE
  3162.       || FUNCTION_ARG_PASS_BY_REFERENCE (args_so_far, passed_mode,
  3163.                           passed_type, ! last_named)
  3164. #endif
  3165.       )
  3166.     {
  3167.       passed_type = build_pointer_type (passed_type);
  3168.       passed_pointer = 1;
  3169.       passed_mode = nominal_mode = Pmode;
  3170.     }
  3171.  
  3172.       promoted_mode = passed_mode;
  3173.  
  3174. #ifdef PROMOTE_FUNCTION_ARGS
  3175.       /* Compute the mode in which the arg is actually extended to.  */
  3176.       promoted_mode = promote_mode (passed_type, promoted_mode, &unsignedp, 1);
  3177. #endif
  3178.  
  3179.       /* Let machine desc say which reg (if any) the parm arrives in.
  3180.      0 means it arrives on the stack.  */
  3181. #ifdef FUNCTION_INCOMING_ARG
  3182.       entry_parm = FUNCTION_INCOMING_ARG (args_so_far, promoted_mode,
  3183.                       passed_type, ! last_named);
  3184. #else
  3185.       entry_parm = FUNCTION_ARG (args_so_far, promoted_mode,
  3186.                  passed_type, ! last_named);
  3187. #endif
  3188.  
  3189.       if (entry_parm)
  3190.     passed_mode = promoted_mode;
  3191.  
  3192. #ifdef SETUP_INCOMING_VARARGS
  3193.       /* If this is the last named parameter, do any required setup for
  3194.      varargs or stdargs.  We need to know about the case of this being an
  3195.      addressable type, in which case we skip the registers it
  3196.      would have arrived in.
  3197.  
  3198.      For stdargs, LAST_NAMED will be set for two parameters, the one that
  3199.      is actually the last named, and the dummy parameter.  We only
  3200.      want to do this action once.
  3201.  
  3202.      Also, indicate when RTL generation is to be suppressed.  */
  3203.       if (last_named && !varargs_setup)
  3204.     {
  3205.       SETUP_INCOMING_VARARGS (args_so_far, passed_mode, passed_type,
  3206.                   current_function_pretend_args_size,
  3207.                   second_time);
  3208.       varargs_setup = 1;
  3209.     }
  3210. #endif
  3211.  
  3212.       /* Determine parm's home in the stack,
  3213.      in case it arrives in the stack or we should pretend it did.
  3214.  
  3215.      Compute the stack position and rtx where the argument arrives
  3216.      and its size.
  3217.  
  3218.      There is one complexity here:  If this was a parameter that would
  3219.      have been passed in registers, but wasn't only because it is
  3220.      __builtin_va_alist, we want locate_and_pad_parm to treat it as if
  3221.      it came in a register so that REG_PARM_STACK_SPACE isn't skipped.
  3222.      In this case, we call FUNCTION_ARG with NAMED set to 1 instead of
  3223.      0 as it was the previous time.  */
  3224.  
  3225.       locate_and_pad_parm (passed_mode, passed_type,
  3226. #ifdef STACK_PARMS_IN_REG_PARM_AREA
  3227.                1,
  3228. #else
  3229. #ifdef FUNCTION_INCOMING_ARG
  3230.                FUNCTION_INCOMING_ARG (args_so_far, passed_mode,
  3231.                           passed_type,
  3232.                           (! last_named
  3233.                            || varargs_setup)) != 0,
  3234. #else
  3235.                FUNCTION_ARG (args_so_far, passed_mode,
  3236.                      passed_type,
  3237.                      ! last_named || varargs_setup) != 0,
  3238. #endif
  3239. #endif
  3240.                fndecl, &stack_args_size, &stack_offset, &arg_size);
  3241.  
  3242.       if (! second_time)
  3243.     {
  3244.       rtx offset_rtx = ARGS_SIZE_RTX (stack_offset);
  3245.  
  3246.       if (offset_rtx == const0_rtx)
  3247.         stack_parm = gen_rtx (MEM, passed_mode, internal_arg_pointer);
  3248.       else
  3249.         stack_parm = gen_rtx (MEM, passed_mode,
  3250.                   gen_rtx (PLUS, Pmode,
  3251.                        internal_arg_pointer, offset_rtx));
  3252.  
  3253.       /* If this is a memory ref that contains aggregate components,
  3254.          mark it as such for cse and loop optimize.  */
  3255.       MEM_IN_STRUCT_P (stack_parm) = aggregate;
  3256.     }
  3257.  
  3258.       /* If this parameter was passed both in registers and in the stack,
  3259.      use the copy on the stack.  */
  3260.       if (MUST_PASS_IN_STACK (passed_mode, passed_type))
  3261.     entry_parm = 0;
  3262.  
  3263. #ifdef FUNCTION_ARG_PARTIAL_NREGS
  3264.       /* If this parm was passed part in regs and part in memory,
  3265.      pretend it arrived entirely in memory
  3266.      by pushing the register-part onto the stack.
  3267.  
  3268.      In the special case of a DImode or DFmode that is split,
  3269.      we could put it together in a pseudoreg directly,
  3270.      but for now that's not worth bothering with.  */
  3271.  
  3272.       if (entry_parm)
  3273.     {
  3274.       int nregs = FUNCTION_ARG_PARTIAL_NREGS (args_so_far, passed_mode,
  3275.                           passed_type, ! last_named);
  3276.  
  3277.       if (nregs > 0)
  3278.         {
  3279.           current_function_pretend_args_size
  3280.         = (((nregs * UNITS_PER_WORD) + (PARM_BOUNDARY / BITS_PER_UNIT) - 1)
  3281.            / (PARM_BOUNDARY / BITS_PER_UNIT)
  3282.            * (PARM_BOUNDARY / BITS_PER_UNIT));
  3283.  
  3284.           if (! second_time)
  3285.         move_block_from_reg (REGNO (entry_parm),
  3286.                      validize_mem (stack_parm), nregs,
  3287.                      int_size_in_bytes (TREE_TYPE (parm)));
  3288.           entry_parm = stack_parm;
  3289.         }
  3290.     }
  3291. #endif
  3292.  
  3293.       /* If we didn't decide this parm came in a register,
  3294.      by default it came on the stack.  */
  3295.       if (entry_parm == 0)
  3296.     entry_parm = stack_parm;
  3297.  
  3298.       /* Record permanently how this parm was passed.  */
  3299.       if (! second_time)
  3300.     DECL_INCOMING_RTL (parm) = entry_parm;
  3301.  
  3302.       /* If there is actually space on the stack for this parm,
  3303.      count it in stack_args_size; otherwise set stack_parm to 0
  3304.      to indicate there is no preallocated stack slot for the parm.  */
  3305.  
  3306.       if (entry_parm == stack_parm
  3307. #if defined (REG_PARM_STACK_SPACE) && ! defined (MAYBE_REG_PARM_STACK_SPACE)
  3308.       /* On some machines, even if a parm value arrives in a register
  3309.          there is still an (uninitialized) stack slot allocated for it.
  3310.  
  3311.          ??? When MAYBE_REG_PARM_STACK_SPACE is defined, we can't tell
  3312.          whether this parameter already has a stack slot allocated,
  3313.          because an arg block exists only if current_function_args_size
  3314.          is larger than some threshhold, and we haven't calculated that
  3315.          yet.  So, for now, we just assume that stack slots never exist
  3316.          in this case.  */
  3317.       || REG_PARM_STACK_SPACE (fndecl) > 0
  3318. #endif
  3319.       )
  3320.     {
  3321.       stack_args_size.constant += arg_size.constant;
  3322.       if (arg_size.var)
  3323.         ADD_PARM_SIZE (stack_args_size, arg_size.var);
  3324.     }
  3325.       else
  3326.     /* No stack slot was pushed for this parm.  */
  3327.     stack_parm = 0;
  3328.  
  3329.       /* Update info on where next arg arrives in registers.  */
  3330.  
  3331.       FUNCTION_ARG_ADVANCE (args_so_far, passed_mode,
  3332.                 passed_type, ! last_named);
  3333.  
  3334.       /* If this is our second time through, we are done with this parm. */
  3335.       if (second_time)
  3336.     continue;
  3337.  
  3338.       /* If we can't trust the parm stack slot to be aligned enough
  3339.      for its ultimate type, don't use that slot after entry.
  3340.      We'll make another stack slot, if we need one.  */
  3341.       {
  3342.     int thisparm_boundary
  3343.       = FUNCTION_ARG_BOUNDARY (passed_mode, passed_type);
  3344.  
  3345.     if (GET_MODE_ALIGNMENT (nominal_mode) > thisparm_boundary)
  3346.       stack_parm = 0;
  3347.       }
  3348.  
  3349.       /* If parm was passed in memory, and we need to convert it on entry,
  3350.      don't store it back in that same slot.  */
  3351.       if (entry_parm != 0
  3352.       && nominal_mode != BLKmode && nominal_mode != passed_mode)
  3353.     stack_parm = 0;
  3354.  
  3355. #if 0
  3356.       /* Now adjust STACK_PARM to the mode and precise location
  3357.      where this parameter should live during execution,
  3358.      if we discover that it must live in the stack during execution.
  3359.      To make debuggers happier on big-endian machines, we store
  3360.      the value in the last bytes of the space available.  */
  3361.  
  3362.       if (nominal_mode != BLKmode && nominal_mode != passed_mode
  3363.       && stack_parm != 0)
  3364.     {
  3365.       rtx offset_rtx;
  3366.  
  3367. #if BYTES_BIG_ENDIAN
  3368.       if (GET_MODE_SIZE (nominal_mode) < UNITS_PER_WORD)
  3369.         stack_offset.constant += (GET_MODE_SIZE (passed_mode)
  3370.                       - GET_MODE_SIZE (nominal_mode));
  3371. #endif
  3372.  
  3373.       offset_rtx = ARGS_SIZE_RTX (stack_offset);
  3374.       if (offset_rtx == const0_rtx)
  3375.         stack_parm = gen_rtx (MEM, nominal_mode, internal_arg_pointer);
  3376.       else
  3377.         stack_parm = gen_rtx (MEM, nominal_mode,
  3378.                   gen_rtx (PLUS, Pmode,
  3379.                        internal_arg_pointer, offset_rtx));
  3380.  
  3381.       /* If this is a memory ref that contains aggregate components,
  3382.          mark it as such for cse and loop optimize.  */
  3383.       MEM_IN_STRUCT_P (stack_parm) = aggregate;
  3384.     }
  3385. #endif /* 0 */
  3386.  
  3387.       /* ENTRY_PARM is an RTX for the parameter as it arrives,
  3388.      in the mode in which it arrives.
  3389.      STACK_PARM is an RTX for a stack slot where the parameter can live
  3390.      during the function (in case we want to put it there).
  3391.      STACK_PARM is 0 if no stack slot was pushed for it.
  3392.  
  3393.      Now output code if necessary to convert ENTRY_PARM to
  3394.      the type in which this function declares it,
  3395.      and store that result in an appropriate place,
  3396.      which may be a pseudo reg, may be STACK_PARM,
  3397.      or may be a local stack slot if STACK_PARM is 0.
  3398.  
  3399.      Set DECL_RTL to that place.  */
  3400.  
  3401.       if (nominal_mode == BLKmode)
  3402.     {
  3403.       /* If a BLKmode arrives in registers, copy it to a stack slot.  */
  3404.       if (GET_CODE (entry_parm) == REG)
  3405.         {
  3406.           int size_stored = CEIL_ROUND (int_size_in_bytes (TREE_TYPE (parm)),
  3407.                         UNITS_PER_WORD);
  3408.  
  3409.           /* Note that we will be storing an integral number of words.
  3410.          So we have to be careful to ensure that we allocate an
  3411.          integral number of words.  We do this below in the
  3412.          assign_stack_local if space was not allocated in the argument
  3413.          list.  If it was, this will not work if PARM_BOUNDARY is not
  3414.          a multiple of BITS_PER_WORD.  It isn't clear how to fix this
  3415.          if it becomes a problem.  */
  3416.  
  3417.           if (stack_parm == 0)
  3418.         {
  3419.           stack_parm
  3420.             = assign_stack_local (GET_MODE (entry_parm), size_stored, 0);
  3421.           /* If this is a memory ref that contains aggregate components,
  3422.              mark it as such for cse and loop optimize.  */
  3423.           MEM_IN_STRUCT_P (stack_parm) = aggregate;
  3424.         }
  3425.  
  3426.           else if (PARM_BOUNDARY % BITS_PER_WORD != 0)
  3427.         abort ();
  3428.  
  3429.           move_block_from_reg (REGNO (entry_parm),
  3430.                    validize_mem (stack_parm),
  3431.                    size_stored / UNITS_PER_WORD,
  3432.                    int_size_in_bytes (TREE_TYPE (parm)));
  3433.         }
  3434.       DECL_RTL (parm) = stack_parm;
  3435.     }
  3436.       else if (! ((obey_regdecls && ! DECL_REGISTER (parm)
  3437.            && ! DECL_INLINE (fndecl))
  3438.           /* layout_decl may set this.  */
  3439.           || TREE_ADDRESSABLE (parm)
  3440.           || TREE_SIDE_EFFECTS (parm)
  3441.           /* If -ffloat-store specified, don't put explicit
  3442.              float variables into registers.  */
  3443.           || (flag_float_store
  3444.               && TREE_CODE (TREE_TYPE (parm)) == REAL_TYPE))
  3445.            /* Always assign pseudo to structure return or item passed
  3446.           by invisible reference.  */
  3447.            || passed_pointer || parm == function_result_decl)
  3448.     {
  3449.       /* Store the parm in a pseudoregister during the function, but we
  3450.          may need to do it in a wider mode.  */
  3451.  
  3452.       register rtx parmreg;
  3453.       int regno, regnoi, regnor;
  3454.  
  3455.       unsignedp = TREE_UNSIGNED (TREE_TYPE (parm));
  3456.       nominal_mode = promote_mode (TREE_TYPE (parm), nominal_mode,
  3457.                        &unsignedp, 1);
  3458.  
  3459.       parmreg = gen_reg_rtx (nominal_mode);
  3460.       REG_USERVAR_P (parmreg) = 1;
  3461.  
  3462.       /* If this was an item that we received a pointer to, set DECL_RTL
  3463.          appropriately.  */
  3464.       if (passed_pointer)
  3465.         {
  3466.           DECL_RTL (parm) = gen_rtx (MEM, TYPE_MODE (TREE_TYPE (passed_type)), parmreg);
  3467.           MEM_IN_STRUCT_P (DECL_RTL (parm)) = aggregate;
  3468.         }
  3469.       else
  3470.         DECL_RTL (parm) = parmreg;
  3471.  
  3472.       /* Copy the value into the register.  */
  3473.       if (GET_MODE (parmreg) != GET_MODE (entry_parm))
  3474.         {
  3475.           /* If ENTRY_PARM is a hard register, it might be in a register
  3476.          not valid for operating in its mode (e.g., an odd-numbered
  3477.          register for a DFmode).  In that case, moves are the only
  3478.          thing valid, so we can't do a convert from there.  This
  3479.          occurs when the calling sequence allow such misaligned
  3480.          usages.
  3481.  
  3482.          In addition, the conversion may involve a call, which could
  3483.          clobber parameters which haven't been copied to pseudo
  3484.          registers yet.  Therefore, we must first copy the parm to
  3485.          a pseudo reg here, and save the conversion until after all
  3486.          parameters have been moved.  */
  3487.  
  3488.           rtx tempreg = gen_reg_rtx (GET_MODE (entry_parm));
  3489.  
  3490.           emit_move_insn (tempreg, validize_mem (entry_parm));
  3491.  
  3492.           push_to_sequence (conversion_insns);
  3493.           convert_move (parmreg, tempreg, unsignedp);
  3494.           conversion_insns = get_insns ();
  3495.           end_sequence ();
  3496.         }
  3497.       else
  3498.         emit_move_insn (parmreg, validize_mem (entry_parm));
  3499.  
  3500.       /* If we were passed a pointer but the actual value
  3501.          can safely live in a register, put it in one.  */
  3502.       if (passed_pointer && TYPE_MODE (TREE_TYPE (parm)) != BLKmode
  3503.           && ! ((obey_regdecls && ! DECL_REGISTER (parm)
  3504.              && ! DECL_INLINE (fndecl))
  3505.             /* layout_decl may set this.  */
  3506.             || TREE_ADDRESSABLE (parm)
  3507.             || TREE_SIDE_EFFECTS (parm)
  3508.             /* If -ffloat-store specified, don't put explicit
  3509.                float variables into registers.  */
  3510.             || (flag_float_store
  3511.             && TREE_CODE (TREE_TYPE (parm)) == REAL_TYPE)))
  3512.         {
  3513.           /* We can't use nominal_mode, because it will have been set to
  3514.          Pmode above.  We must use the actual mode of the parm.  */
  3515.           parmreg = gen_reg_rtx (TYPE_MODE (TREE_TYPE (parm)));
  3516.           REG_USERVAR_P (parmreg) = 1;
  3517.           emit_move_insn (parmreg, DECL_RTL (parm));
  3518.           DECL_RTL (parm) = parmreg;
  3519.           /* STACK_PARM is the pointer, not the parm, and PARMREG is
  3520.          now the parm.  */
  3521.           stack_parm = 0;
  3522.         }
  3523. #ifdef FUNCTION_ARG_CALLEE_COPIES
  3524.       /* If we are passed an arg by reference and it is our responsibility
  3525.          to make a copy, do it now.
  3526.          PASSED_TYPE and PASSED mode now refer to the pointer, not the
  3527.          original argument, so we must recreate them in the call to
  3528.          FUNCTION_ARG_CALLEE_COPIES.  */
  3529.       /* ??? Later add code to handle the case that if the argument isn't
  3530.          modified, don't do the copy.  */
  3531.  
  3532.       else if (passed_pointer
  3533.            && FUNCTION_ARG_CALLEE_COPIES (args_so_far,
  3534.                           TYPE_MODE (DECL_ARG_TYPE (parm)),
  3535.                           DECL_ARG_TYPE (parm),
  3536.                           ! last_named))
  3537.         {
  3538.           rtx copy;
  3539.           tree type = DECL_ARG_TYPE (parm);
  3540.  
  3541.           /* This sequence may involve a library call perhaps clobbering
  3542.          registers that haven't been copied to pseudos yet.  */
  3543.  
  3544.           push_to_sequence (conversion_insns);
  3545.  
  3546.           if (TYPE_SIZE (type) == 0
  3547.           || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
  3548.         /* This is a variable sized object.  */
  3549.         copy = gen_rtx (MEM, BLKmode,
  3550.                 allocate_dynamic_stack_space
  3551.                 (expr_size (parm), NULL_RTX,
  3552.                  TYPE_ALIGN (type)));
  3553.           else
  3554.         copy = assign_stack_temp (TYPE_MODE (type),
  3555.                       int_size_in_bytes (type), 1);
  3556.  
  3557.           store_expr (parm, copy, 0);
  3558.           emit_move_insn (parmreg, XEXP (copy, 0));
  3559.           conversion_insns = get_insns ();
  3560.           end_sequence ();
  3561.         }
  3562. #endif /* FUNCTION_ARG_CALLEE_COPIES */
  3563.  
  3564.       /* In any case, record the parm's desired stack location
  3565.          in case we later discover it must live in the stack. 
  3566.  
  3567.          If it is a COMPLEX value, store the stack location for both
  3568.          halves.  */
  3569.  
  3570.       if (GET_CODE (parmreg) == CONCAT)
  3571.         regno = MAX (REGNO (XEXP (parmreg, 0)), REGNO (XEXP (parmreg, 1)));
  3572.       else
  3573.         regno = REGNO (parmreg);
  3574.  
  3575.       if (regno >= nparmregs)
  3576.         {
  3577.           rtx *new;
  3578.           int old_nparmregs = nparmregs;
  3579.  
  3580.           nparmregs = regno + 5;
  3581.           new = (rtx *) oballoc (nparmregs * sizeof (rtx));
  3582.           bcopy ((char *) parm_reg_stack_loc, (char *) new,
  3583.              old_nparmregs * sizeof (rtx));
  3584.           bzero ((char *) (new + old_nparmregs),
  3585.              (nparmregs - old_nparmregs) * sizeof (rtx));
  3586.           parm_reg_stack_loc = new;
  3587.         }
  3588.  
  3589.       if (GET_CODE (parmreg) == CONCAT)
  3590.         {
  3591.           enum machine_mode submode = GET_MODE (XEXP (parmreg, 0));
  3592.  
  3593.           regnor = REGNO (gen_realpart (submode, parmreg));
  3594.           regnoi = REGNO (gen_imagpart (submode, parmreg));
  3595.  
  3596.           if (stack_parm != 0)
  3597.         {
  3598.           parm_reg_stack_loc[regnor]
  3599.             = gen_realpart (submode, stack_parm);
  3600.           parm_reg_stack_loc[regnoi]
  3601.             = gen_imagpart (submode, stack_parm);
  3602.         }
  3603.           else
  3604.         {
  3605.           parm_reg_stack_loc[regnor] = 0;
  3606.           parm_reg_stack_loc[regnoi] = 0;
  3607.         }
  3608.         }
  3609.       else
  3610.         parm_reg_stack_loc[REGNO (parmreg)] = stack_parm;
  3611.  
  3612.       /* Mark the register as eliminable if we did no conversion
  3613.          and it was copied from memory at a fixed offset,
  3614.          and the arg pointer was not copied to a pseudo-reg.
  3615.          If the arg pointer is a pseudo reg or the offset formed
  3616.          an invalid address, such memory-equivalences
  3617.          as we make here would screw up life analysis for it.  */
  3618.       if (nominal_mode == passed_mode
  3619.           && ! conversion_insns
  3620.           && GET_CODE (entry_parm) == MEM
  3621.           && entry_parm == stack_parm
  3622.           && stack_offset.var == 0
  3623.           && reg_mentioned_p (virtual_incoming_args_rtx,
  3624.                   XEXP (entry_parm, 0)))
  3625.         {
  3626.           rtx linsn = get_last_insn ();
  3627.  
  3628.           /* Mark complex types separately.  */
  3629.           if (GET_CODE (parmreg) == CONCAT)
  3630.             {
  3631.               REG_NOTES (linsn)
  3632.                   = gen_rtx (EXPR_LIST, REG_EQUIV,
  3633.                  parm_reg_stack_loc[regnoi], REG_NOTES (linsn));
  3634.  
  3635.           /* Now search backward for where we set the real part.  */
  3636.           for (; linsn != 0
  3637.                && ! reg_referenced_p (parm_reg_stack_loc[regnor],
  3638.                           PATTERN (linsn));
  3639.                linsn = prev_nonnote_insn (linsn))
  3640.             ;
  3641.  
  3642.               REG_NOTES (linsn)
  3643.                   = gen_rtx (EXPR_LIST, REG_EQUIV,
  3644.                  parm_reg_stack_loc[regnor], REG_NOTES (linsn));
  3645.         }
  3646.           else
  3647.             REG_NOTES (linsn)
  3648.              = gen_rtx (EXPR_LIST, REG_EQUIV,
  3649.                 entry_parm, REG_NOTES (linsn));
  3650.         }
  3651.  
  3652.       /* For pointer data type, suggest pointer register.  */
  3653.       if (TREE_CODE (TREE_TYPE (parm)) == POINTER_TYPE)
  3654.         mark_reg_pointer (parmreg);
  3655.     }
  3656.       else
  3657.     {
  3658.       /* Value must be stored in the stack slot STACK_PARM
  3659.          during function execution.  */
  3660.  
  3661.       if (passed_mode != nominal_mode)
  3662.         {
  3663.           /* Conversion is required.   */
  3664.           rtx tempreg = gen_reg_rtx (GET_MODE (entry_parm));
  3665.  
  3666.           emit_move_insn (tempreg, validize_mem (entry_parm));
  3667.  
  3668.           push_to_sequence (conversion_insns);
  3669.           entry_parm = convert_to_mode (nominal_mode, tempreg,
  3670.                         TREE_UNSIGNED (TREE_TYPE (parm)));
  3671.           conversion_insns = get_insns ();
  3672.           end_sequence ();
  3673.         }
  3674.  
  3675.       if (entry_parm != stack_parm)
  3676.         {
  3677.           if (stack_parm == 0)
  3678.         {
  3679.           stack_parm
  3680.             = assign_stack_local (GET_MODE (entry_parm),
  3681.                       GET_MODE_SIZE (GET_MODE (entry_parm)), 0);
  3682.           /* If this is a memory ref that contains aggregate components,
  3683.              mark it as such for cse and loop optimize.  */
  3684.           MEM_IN_STRUCT_P (stack_parm) = aggregate;
  3685.         }
  3686.  
  3687.           if (passed_mode != nominal_mode)
  3688.         {
  3689.           push_to_sequence (conversion_insns);
  3690.           emit_move_insn (validize_mem (stack_parm),
  3691.                   validize_mem (entry_parm));
  3692.           conversion_insns = get_insns ();
  3693.           end_sequence ();
  3694.         }
  3695.           else
  3696.         emit_move_insn (validize_mem (stack_parm),
  3697.                 validize_mem (entry_parm));
  3698.         }
  3699.  
  3700.       DECL_RTL (parm) = stack_parm;
  3701.     }
  3702.       
  3703.       /* If this "parameter" was the place where we are receiving the
  3704.      function's incoming structure pointer, set up the result.  */
  3705.       if (parm == function_result_decl)
  3706.     {
  3707.       tree result = DECL_RESULT (fndecl);
  3708.       tree restype = TREE_TYPE (result);
  3709.  
  3710.       DECL_RTL (result)
  3711.         = gen_rtx (MEM, DECL_MODE (result), DECL_RTL (parm));
  3712.  
  3713.       MEM_IN_STRUCT_P (DECL_RTL (result)) = AGGREGATE_TYPE_P (restype);
  3714.     }
  3715.  
  3716.       if (TREE_THIS_VOLATILE (parm))
  3717.     MEM_VOLATILE_P (DECL_RTL (parm)) = 1;
  3718.       if (TREE_READONLY (parm))
  3719.     RTX_UNCHANGING_P (DECL_RTL (parm)) = 1;
  3720.     }
  3721.  
  3722.   /* Output all parameter conversion instructions (possibly including calls)
  3723.      now that all parameters have been copied out of hard registers.  */
  3724.   emit_insns (conversion_insns);
  3725.  
  3726.   max_parm_reg = max_reg_num ();
  3727.   last_parm_insn = get_last_insn ();
  3728.  
  3729.   current_function_args_size = stack_args_size.constant;
  3730.  
  3731.   /* Adjust function incoming argument size for alignment and
  3732.      minimum length.  */
  3733.  
  3734. #ifdef REG_PARM_STACK_SPACE
  3735. #ifndef MAYBE_REG_PARM_STACK_SPACE
  3736.   current_function_args_size = MAX (current_function_args_size,
  3737.                     REG_PARM_STACK_SPACE (fndecl));
  3738. #endif
  3739. #endif
  3740.  
  3741. #ifdef STACK_BOUNDARY
  3742. #define STACK_BYTES (STACK_BOUNDARY / BITS_PER_UNIT)
  3743.  
  3744.   current_function_args_size
  3745.     = ((current_function_args_size + STACK_BYTES - 1)
  3746.        / STACK_BYTES) * STACK_BYTES;
  3747. #endif  
  3748.  
  3749. #ifdef ARGS_GROW_DOWNWARD
  3750.   current_function_arg_offset_rtx
  3751.     = (stack_args_size.var == 0 ? GEN_INT (-stack_args_size.constant)
  3752.        : expand_expr (size_binop (MINUS_EXPR, stack_args_size.var,    
  3753.                   size_int (-stack_args_size.constant)),   
  3754.               NULL_RTX, VOIDmode, 0));
  3755. #else
  3756.   current_function_arg_offset_rtx = ARGS_SIZE_RTX (stack_args_size);
  3757. #endif
  3758.  
  3759.   /* See how many bytes, if any, of its args a function should try to pop
  3760.      on return.  */
  3761.  
  3762.   current_function_pops_args = RETURN_POPS_ARGS (TREE_TYPE (fndecl),
  3763.                          current_function_args_size);
  3764.  
  3765.   /* For stdarg.h function, save info about
  3766.      regs and stack space used by the named args.  */
  3767.  
  3768.   if (!hide_last_arg)
  3769.     current_function_args_info = args_so_far;
  3770.  
  3771.   /* Set the rtx used for the function return value.  Put this in its
  3772.      own variable so any optimizers that need this information don't have
  3773.      to include tree.h.  Do this here so it gets done when an inlined
  3774.      function gets output.  */
  3775.  
  3776.   current_function_return_rtx = DECL_RTL (DECL_RESULT (fndecl));
  3777. }
  3778.  
  3779. /* Indicate whether REGNO is an incoming argument to the current function
  3780.    that was promoted to a wider mode.  If so, return the RTX for the
  3781.    register (to get its mode).  PMODE and PUNSIGNEDP are set to the mode
  3782.    that REGNO is promoted from and whether the promotion was signed or
  3783.    unsigned.  */
  3784.  
  3785. #ifdef PROMOTE_FUNCTION_ARGS
  3786.  
  3787. rtx
  3788. promoted_input_arg (regno, pmode, punsignedp)
  3789.      int regno;
  3790.      enum machine_mode *pmode;
  3791.      int *punsignedp;
  3792. {
  3793.   tree arg;
  3794.  
  3795.   for (arg = DECL_ARGUMENTS (current_function_decl); arg;
  3796.        arg = TREE_CHAIN (arg))
  3797.     if (GET_CODE (DECL_INCOMING_RTL (arg)) == REG
  3798.     && REGNO (DECL_INCOMING_RTL (arg)) == regno)
  3799.       {
  3800.     enum machine_mode mode = TYPE_MODE (TREE_TYPE (arg));
  3801.     int unsignedp = TREE_UNSIGNED (TREE_TYPE (arg));
  3802.  
  3803.     mode = promote_mode (TREE_TYPE (arg), mode, &unsignedp, 1);
  3804.     if (mode == GET_MODE (DECL_INCOMING_RTL (arg))
  3805.         && mode != DECL_MODE (arg))
  3806.       {
  3807.         *pmode = DECL_MODE (arg);
  3808.         *punsignedp = unsignedp;
  3809.         return DECL_INCOMING_RTL (arg);
  3810.       }
  3811.       }
  3812.  
  3813.   return 0;
  3814. }
  3815.  
  3816. #endif
  3817.  
  3818. /* Compute the size and offset from the start of the stacked arguments for a
  3819.    parm passed in mode PASSED_MODE and with type TYPE.
  3820.  
  3821.    INITIAL_OFFSET_PTR points to the current offset into the stacked
  3822.    arguments.
  3823.  
  3824.    The starting offset and size for this parm are returned in *OFFSET_PTR
  3825.    and *ARG_SIZE_PTR, respectively.
  3826.  
  3827.    IN_REGS is non-zero if the argument will be passed in registers.  It will
  3828.    never be set if REG_PARM_STACK_SPACE is not defined.
  3829.  
  3830.    FNDECL is the function in which the argument was defined.
  3831.  
  3832.    There are two types of rounding that are done.  The first, controlled by
  3833.    FUNCTION_ARG_BOUNDARY, forces the offset from the start of the argument
  3834.    list to be aligned to the specific boundary (in bits).  This rounding
  3835.    affects the initial and starting offsets, but not the argument size.
  3836.  
  3837.    The second, controlled by FUNCTION_ARG_PADDING and PARM_BOUNDARY,
  3838.    optionally rounds the size of the parm to PARM_BOUNDARY.  The
  3839.    initial offset is not affected by this rounding, while the size always
  3840.    is and the starting offset may be.  */
  3841.  
  3842. /*  offset_ptr will be negative for ARGS_GROW_DOWNWARD case; 
  3843.     initial_offset_ptr is positive because locate_and_pad_parm's
  3844.     callers pass in the total size of args so far as
  3845.     initial_offset_ptr. arg_size_ptr is always positive.*/
  3846.  
  3847. void
  3848. locate_and_pad_parm (passed_mode, type, in_regs, fndecl,
  3849.              initial_offset_ptr, offset_ptr, arg_size_ptr)
  3850.      enum machine_mode passed_mode;
  3851.      tree type;
  3852.      int in_regs;
  3853.      tree fndecl;
  3854.      struct args_size *initial_offset_ptr;
  3855.      struct args_size *offset_ptr;
  3856.      struct args_size *arg_size_ptr;
  3857. {
  3858.   tree sizetree
  3859.     = type ? size_in_bytes (type) : size_int (GET_MODE_SIZE (passed_mode));
  3860.   enum direction where_pad = FUNCTION_ARG_PADDING (passed_mode, type);
  3861.   int boundary = FUNCTION_ARG_BOUNDARY (passed_mode, type);
  3862.   int boundary_in_bytes = boundary / BITS_PER_UNIT;
  3863.   int reg_parm_stack_space = 0;
  3864.  
  3865. #ifdef REG_PARM_STACK_SPACE
  3866.   /* If we have found a stack parm before we reach the end of the
  3867.      area reserved for registers, skip that area.  */
  3868.   if (! in_regs)
  3869.     {
  3870. #ifdef MAYBE_REG_PARM_STACK_SPACE
  3871.       reg_parm_stack_space = MAYBE_REG_PARM_STACK_SPACE;
  3872. #else
  3873.       reg_parm_stack_space = REG_PARM_STACK_SPACE (fndecl);
  3874. #endif
  3875.       if (reg_parm_stack_space > 0)
  3876.     {
  3877.       if (initial_offset_ptr->var)
  3878.         {
  3879.           initial_offset_ptr->var
  3880.         = size_binop (MAX_EXPR, ARGS_SIZE_TREE (*initial_offset_ptr),
  3881.                   size_int (reg_parm_stack_space));
  3882.           initial_offset_ptr->constant = 0;
  3883.         }
  3884.       else if (initial_offset_ptr->constant < reg_parm_stack_space)
  3885.         initial_offset_ptr->constant = reg_parm_stack_space;
  3886.     }
  3887.     }
  3888. #endif /* REG_PARM_STACK_SPACE */
  3889.  
  3890.   arg_size_ptr->var = 0;
  3891.   arg_size_ptr->constant = 0;
  3892.  
  3893. #ifdef ARGS_GROW_DOWNWARD
  3894.   if (initial_offset_ptr->var)
  3895.     {
  3896.       offset_ptr->constant = 0;
  3897.       offset_ptr->var = size_binop (MINUS_EXPR, integer_zero_node,
  3898.                     initial_offset_ptr->var);
  3899.     }
  3900.   else
  3901.     {
  3902.       offset_ptr->constant = - initial_offset_ptr->constant;
  3903.       offset_ptr->var = 0;
  3904.     }
  3905.   if (where_pad != none
  3906.       && (TREE_CODE (sizetree) != INTEGER_CST
  3907.       || ((TREE_INT_CST_LOW (sizetree) * BITS_PER_UNIT) % PARM_BOUNDARY)))
  3908.     sizetree = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT);
  3909.   SUB_PARM_SIZE (*offset_ptr, sizetree);
  3910.   if (where_pad != downward)
  3911.     pad_to_arg_alignment (offset_ptr, boundary);
  3912.   if (initial_offset_ptr->var)
  3913.     {
  3914.       arg_size_ptr->var = size_binop (MINUS_EXPR,
  3915.                       size_binop (MINUS_EXPR,
  3916.                           integer_zero_node,
  3917.                           initial_offset_ptr->var),
  3918.                       offset_ptr->var);
  3919.     }
  3920.   else
  3921.     {
  3922.       arg_size_ptr->constant = (- initial_offset_ptr->constant -
  3923.                 offset_ptr->constant); 
  3924.     }
  3925. #else /* !ARGS_GROW_DOWNWARD */
  3926.   pad_to_arg_alignment (initial_offset_ptr, boundary);
  3927.   *offset_ptr = *initial_offset_ptr;
  3928.  
  3929. #ifdef PUSH_ROUNDING
  3930.   if (passed_mode != BLKmode)
  3931.     sizetree = size_int (PUSH_ROUNDING (TREE_INT_CST_LOW (sizetree)));
  3932. #endif
  3933.  
  3934.   if (where_pad != none
  3935.       && (TREE_CODE (sizetree) != INTEGER_CST
  3936.       || ((TREE_INT_CST_LOW (sizetree) * BITS_PER_UNIT) % PARM_BOUNDARY)))
  3937.     sizetree = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT);
  3938.  
  3939.   /* This must be done after rounding sizetree, so that it will subtract
  3940.      the same value that we explicitly add below.  */
  3941.   if (where_pad == downward)
  3942.     pad_below (offset_ptr, passed_mode, sizetree);
  3943.   ADD_PARM_SIZE (*arg_size_ptr, sizetree);
  3944. #endif /* ARGS_GROW_DOWNWARD */
  3945. }
  3946.  
  3947. /* Round the stack offset in *OFFSET_PTR up to a multiple of BOUNDARY.
  3948.    BOUNDARY is measured in bits, but must be a multiple of a storage unit.  */
  3949.  
  3950. static void
  3951. pad_to_arg_alignment (offset_ptr, boundary)
  3952.      struct args_size *offset_ptr;
  3953.      int boundary;
  3954. {
  3955.   int boundary_in_bytes = boundary / BITS_PER_UNIT;
  3956.   
  3957.   if (boundary > BITS_PER_UNIT)
  3958.     {
  3959.       if (offset_ptr->var)
  3960.     {
  3961.       offset_ptr->var  =
  3962. #ifdef ARGS_GROW_DOWNWARD
  3963.         round_down 
  3964. #else
  3965.         round_up
  3966. #endif
  3967.           (ARGS_SIZE_TREE (*offset_ptr),
  3968.            boundary / BITS_PER_UNIT);
  3969.       offset_ptr->constant = 0; /*?*/
  3970.     }
  3971.       else
  3972.     offset_ptr->constant =
  3973. #ifdef ARGS_GROW_DOWNWARD
  3974.       FLOOR_ROUND (offset_ptr->constant, boundary_in_bytes);
  3975. #else
  3976.       CEIL_ROUND (offset_ptr->constant, boundary_in_bytes);
  3977. #endif
  3978.     }
  3979. }
  3980.  
  3981. static void
  3982. pad_below (offset_ptr, passed_mode, sizetree)
  3983.      struct args_size *offset_ptr;
  3984.      enum machine_mode passed_mode;
  3985.      tree sizetree;
  3986. {
  3987.   if (passed_mode != BLKmode)
  3988.     {
  3989.       if (GET_MODE_BITSIZE (passed_mode) % PARM_BOUNDARY)
  3990.     offset_ptr->constant
  3991.       += (((GET_MODE_BITSIZE (passed_mode) + PARM_BOUNDARY - 1)
  3992.            / PARM_BOUNDARY * PARM_BOUNDARY / BITS_PER_UNIT)
  3993.           - GET_MODE_SIZE (passed_mode));
  3994.     }
  3995.   else
  3996.     {
  3997.       if (TREE_CODE (sizetree) != INTEGER_CST
  3998.       || (TREE_INT_CST_LOW (sizetree) * BITS_PER_UNIT) % PARM_BOUNDARY)
  3999.     {
  4000.       /* Round the size up to multiple of PARM_BOUNDARY bits.  */
  4001.       tree s2 = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT);
  4002.       /* Add it in.  */
  4003.       ADD_PARM_SIZE (*offset_ptr, s2);
  4004.       SUB_PARM_SIZE (*offset_ptr, sizetree);
  4005.     }
  4006.     }
  4007. }
  4008.  
  4009. static tree
  4010. round_down (value, divisor)
  4011.      tree value;
  4012.      int divisor;
  4013. {
  4014.   return size_binop (MULT_EXPR,
  4015.              size_binop (FLOOR_DIV_EXPR, value, size_int (divisor)),
  4016.              size_int (divisor));
  4017. }
  4018.  
  4019. /* Walk the tree of blocks describing the binding levels within a function
  4020.    and warn about uninitialized variables.
  4021.    This is done after calling flow_analysis and before global_alloc
  4022.    clobbers the pseudo-regs to hard regs.  */
  4023.  
  4024. void
  4025. uninitialized_vars_warning (block)
  4026.      tree block;
  4027. {
  4028.   register tree decl, sub;
  4029.   for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
  4030.     {
  4031.       if (TREE_CODE (decl) == VAR_DECL
  4032.       /* These warnings are unreliable for and aggregates
  4033.          because assigning the fields one by one can fail to convince
  4034.          flow.c that the entire aggregate was initialized.
  4035.          Unions are troublesome because members may be shorter.  */
  4036.       && ! AGGREGATE_TYPE_P (TREE_TYPE (decl))
  4037.       && DECL_RTL (decl) != 0
  4038.       && GET_CODE (DECL_RTL (decl)) == REG
  4039.       && regno_uninitialized (REGNO (DECL_RTL (decl))))
  4040.     warning_with_decl (decl,
  4041.                "`%s' might be used uninitialized in this function");
  4042.       if (TREE_CODE (decl) == VAR_DECL
  4043.       && DECL_RTL (decl) != 0
  4044.       && GET_CODE (DECL_RTL (decl)) == REG
  4045.       && regno_clobbered_at_setjmp (REGNO (DECL_RTL (decl))))
  4046.     warning_with_decl (decl,
  4047.                "variable `%s' might be clobbered by `longjmp' or `vfork'");
  4048.     }
  4049.   for (sub = BLOCK_SUBBLOCKS (block); sub; sub = TREE_CHAIN (sub))
  4050.     uninitialized_vars_warning (sub);
  4051. }
  4052.  
  4053. /* Do the appropriate part of uninitialized_vars_warning
  4054.    but for arguments instead of local variables.  */
  4055.  
  4056. void
  4057. setjmp_args_warning (block)
  4058.      tree block;
  4059. {
  4060.   register tree decl;
  4061.   for (decl = DECL_ARGUMENTS (current_function_decl);
  4062.        decl; decl = TREE_CHAIN (decl))
  4063.     if (DECL_RTL (decl) != 0
  4064.     && GET_CODE (DECL_RTL (decl)) == REG
  4065.     && regno_clobbered_at_setjmp (REGNO (DECL_RTL (decl))))
  4066.       warning_with_decl (decl, "argument `%s' might be clobbered by `longjmp' or `vfork'");
  4067. }
  4068.  
  4069. /* If this function call setjmp, put all vars into the stack
  4070.    unless they were declared `register'.  */
  4071.  
  4072. void
  4073. setjmp_protect (block)
  4074.      tree block;
  4075. {
  4076.   register tree decl, sub;
  4077.   for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
  4078.     if ((TREE_CODE (decl) == VAR_DECL
  4079.      || TREE_CODE (decl) == PARM_DECL)
  4080.     && DECL_RTL (decl) != 0
  4081.     && GET_CODE (DECL_RTL (decl)) == REG
  4082.     /* If this variable came from an inline function, it must be
  4083.        that it's life doesn't overlap the setjmp.  If there was a
  4084.        setjmp in the function, it would already be in memory.  We
  4085.        must exclude such variable because their DECL_RTL might be
  4086.        set to strange things such as virtual_stack_vars_rtx.  */
  4087.     && ! DECL_FROM_INLINE (decl)
  4088.     && (
  4089. #ifdef NON_SAVING_SETJMP
  4090.         /* If longjmp doesn't restore the registers,
  4091.            don't put anything in them.  */
  4092.         NON_SAVING_SETJMP
  4093.         ||
  4094. #endif
  4095.         ! DECL_REGISTER (decl)))
  4096.       put_var_into_stack (decl);
  4097.   for (sub = BLOCK_SUBBLOCKS (block); sub; sub = TREE_CHAIN (sub))
  4098.     setjmp_protect (sub);
  4099. }
  4100.  
  4101. /* Like the previous function, but for args instead of local variables.  */
  4102.  
  4103. void
  4104. setjmp_protect_args ()
  4105. {
  4106.   register tree decl, sub;
  4107.   for (decl = DECL_ARGUMENTS (current_function_decl);
  4108.        decl; decl = TREE_CHAIN (decl))
  4109.     if ((TREE_CODE (decl) == VAR_DECL
  4110.      || TREE_CODE (decl) == PARM_DECL)
  4111.     && DECL_RTL (decl) != 0
  4112.     && GET_CODE (DECL_RTL (decl)) == REG
  4113.     && (
  4114.         /* If longjmp doesn't restore the registers,
  4115.            don't put anything in them.  */
  4116. #ifdef NON_SAVING_SETJMP
  4117.         NON_SAVING_SETJMP
  4118.         ||
  4119. #endif
  4120.         ! DECL_REGISTER (decl)))
  4121.       put_var_into_stack (decl);
  4122. }
  4123.  
  4124. /* Return the context-pointer register corresponding to DECL,
  4125.    or 0 if it does not need one.  */
  4126.  
  4127. rtx
  4128. lookup_static_chain (decl)
  4129.      tree decl;
  4130. {
  4131.   tree context = decl_function_context (decl);
  4132.   tree link;
  4133.  
  4134.   if (context == 0)
  4135.     return 0;
  4136.   
  4137.   /* We treat inline_function_decl as an alias for the current function
  4138.      because that is the inline function whose vars, types, etc.
  4139.      are being merged into the current function.
  4140.      See expand_inline_function.  */
  4141.   if (context == current_function_decl || context == inline_function_decl)
  4142.     return virtual_stack_vars_rtx;
  4143.  
  4144.   for (link = context_display; link; link = TREE_CHAIN (link))
  4145.     if (TREE_PURPOSE (link) == context)
  4146.       return RTL_EXPR_RTL (TREE_VALUE (link));
  4147.  
  4148.   abort ();
  4149. }
  4150.  
  4151. /* Convert a stack slot address ADDR for variable VAR
  4152.    (from a containing function)
  4153.    into an address valid in this function (using a static chain).  */
  4154.  
  4155. rtx
  4156. fix_lexical_addr (addr, var)
  4157.      rtx addr;
  4158.      tree var;
  4159. {
  4160.   rtx basereg;
  4161.   int displacement;
  4162.   tree context = decl_function_context (var);
  4163.   struct function *fp;
  4164.   rtx base = 0;
  4165.  
  4166.   /* If this is the present function, we need not do anything.  */
  4167.   if (context == current_function_decl || context == inline_function_decl)
  4168.     return addr;
  4169.  
  4170.   for (fp = outer_function_chain; fp; fp = fp->next)
  4171.     if (fp->decl == context)
  4172.       break;
  4173.  
  4174.   if (fp == 0)
  4175.     abort ();
  4176.  
  4177.   /* Decode given address as base reg plus displacement.  */
  4178.   if (GET_CODE (addr) == REG)
  4179.     basereg = addr, displacement = 0;
  4180.   else if (GET_CODE (addr) == PLUS && GET_CODE (XEXP (addr, 1)) == CONST_INT)
  4181.     basereg = XEXP (addr, 0), displacement = INTVAL (XEXP (addr, 1));
  4182.   else
  4183.     abort ();
  4184.  
  4185.   /* We accept vars reached via the containing function's
  4186.      incoming arg pointer and via its stack variables pointer.  */
  4187.   if (basereg == fp->internal_arg_pointer)
  4188.     {
  4189.       /* If reached via arg pointer, get the arg pointer value
  4190.      out of that function's stack frame.
  4191.  
  4192.      There are two cases:  If a separate ap is needed, allocate a
  4193.      slot in the outer function for it and dereference it that way.
  4194.      This is correct even if the real ap is actually a pseudo.
  4195.      Otherwise, just adjust the offset from the frame pointer to
  4196.      compensate.  */
  4197.  
  4198. #ifdef NEED_SEPARATE_AP
  4199.       rtx addr;
  4200.  
  4201.       if (fp->arg_pointer_save_area == 0)
  4202.     fp->arg_pointer_save_area
  4203.       = assign_outer_stack_local (Pmode, GET_MODE_SIZE (Pmode), 0, fp);
  4204.  
  4205.       addr = fix_lexical_addr (XEXP (fp->arg_pointer_save_area, 0), var);
  4206.       addr = memory_address (Pmode, addr);
  4207.  
  4208.       base = copy_to_reg (gen_rtx (MEM, Pmode, addr));
  4209. #else
  4210.       displacement += (FIRST_PARM_OFFSET (context) - STARTING_FRAME_OFFSET);
  4211.       base = lookup_static_chain (var);
  4212. #endif
  4213.     }
  4214.  
  4215.   else if (basereg == virtual_stack_vars_rtx)
  4216.     {
  4217.       /* This is the same code as lookup_static_chain, duplicated here to
  4218.      avoid an extra call to decl_function_context.  */
  4219.       tree link;
  4220.  
  4221.       for (link = context_display; link; link = TREE_CHAIN (link))
  4222.     if (TREE_PURPOSE (link) == context)
  4223.       {
  4224.         base = RTL_EXPR_RTL (TREE_VALUE (link));
  4225.         break;
  4226.       }
  4227.     }
  4228.  
  4229.   if (base == 0)
  4230.     abort ();
  4231.  
  4232.   /* Use same offset, relative to appropriate static chain or argument
  4233.      pointer.  */
  4234.   return plus_constant (base, displacement);
  4235. }
  4236.  
  4237. /* Return the address of the trampoline for entering nested fn FUNCTION.
  4238.    If necessary, allocate a trampoline (in the stack frame)
  4239.    and emit rtl to initialize its contents (at entry to this function).  */
  4240.  
  4241. rtx
  4242. trampoline_address (function)
  4243.      tree function;
  4244. {
  4245.   tree link;
  4246.   tree rtlexp;
  4247.   rtx tramp;
  4248.   struct function *fp;
  4249.   tree fn_context;
  4250.  
  4251.   /* Find an existing trampoline and return it.  */
  4252.   for (link = trampoline_list; link; link = TREE_CHAIN (link))
  4253.     if (TREE_PURPOSE (link) == function)
  4254.       return XEXP (RTL_EXPR_RTL (TREE_VALUE (link)), 0);
  4255.   for (fp = outer_function_chain; fp; fp = fp->next)
  4256.     for (link = fp->trampoline_list; link; link = TREE_CHAIN (link))
  4257.       if (TREE_PURPOSE (link) == function)
  4258.     {
  4259.       tramp = fix_lexical_addr (XEXP (RTL_EXPR_RTL (TREE_VALUE (link)), 0),
  4260.                     function);
  4261.       return round_trampoline_addr (tramp);
  4262.     }
  4263.  
  4264.   /* None exists; we must make one.  */
  4265.  
  4266.   /* Find the `struct function' for the function containing FUNCTION.  */
  4267.   fp = 0;
  4268.   fn_context = decl_function_context (function);
  4269.   if (fn_context != current_function_decl)
  4270.     for (fp = outer_function_chain; fp; fp = fp->next)
  4271.       if (fp->decl == fn_context)
  4272.     break;
  4273.  
  4274.   /* Allocate run-time space for this trampoline
  4275.      (usually in the defining function's stack frame).  */
  4276. #ifdef ALLOCATE_TRAMPOLINE
  4277.   tramp = ALLOCATE_TRAMPOLINE (fp);
  4278. #else
  4279.   /* If rounding needed, allocate extra space
  4280.      to ensure we have TRAMPOLINE_SIZE bytes left after rounding up.  */
  4281. #ifdef TRAMPOLINE_ALIGNMENT
  4282. #define TRAMPOLINE_REAL_SIZE (TRAMPOLINE_SIZE + TRAMPOLINE_ALIGNMENT - 1)
  4283. #else
  4284. #define TRAMPOLINE_REAL_SIZE (TRAMPOLINE_SIZE)
  4285. #endif
  4286.   if (fp != 0)
  4287.     tramp = assign_outer_stack_local (BLKmode, TRAMPOLINE_REAL_SIZE, 0, fp);
  4288.   else
  4289.     tramp = assign_stack_local (BLKmode, TRAMPOLINE_REAL_SIZE, 0);
  4290. #endif
  4291.  
  4292.   /* Record the trampoline for reuse and note it for later initialization
  4293.      by expand_function_end.  */
  4294.   if (fp != 0)
  4295.     {
  4296.       push_obstacks (fp->function_maybepermanent_obstack,
  4297.              fp->function_maybepermanent_obstack);
  4298.       rtlexp = make_node (RTL_EXPR);
  4299.       RTL_EXPR_RTL (rtlexp) = tramp;
  4300.       fp->trampoline_list = tree_cons (function, rtlexp, fp->trampoline_list);
  4301.       pop_obstacks ();
  4302.     }
  4303.   else
  4304.     {
  4305.       /* Make the RTL_EXPR node temporary, not momentary, so that the
  4306.      trampoline_list doesn't become garbage.  */
  4307.       int momentary = suspend_momentary ();
  4308.       rtlexp = make_node (RTL_EXPR);
  4309.       resume_momentary (momentary);
  4310.  
  4311.       RTL_EXPR_RTL (rtlexp) = tramp;
  4312.       trampoline_list = tree_cons (function, rtlexp, trampoline_list);
  4313.     }
  4314.  
  4315.   tramp = fix_lexical_addr (XEXP (tramp, 0), function);
  4316.   return round_trampoline_addr (tramp);
  4317. }
  4318.  
  4319. /* Given a trampoline address,
  4320.    round it to multiple of TRAMPOLINE_ALIGNMENT.  */
  4321.  
  4322. static rtx
  4323. round_trampoline_addr (tramp)
  4324.      rtx tramp;
  4325. {
  4326. #ifdef TRAMPOLINE_ALIGNMENT
  4327.   /* Round address up to desired boundary.  */
  4328.   rtx temp = gen_reg_rtx (Pmode);
  4329.   temp = expand_binop (Pmode, add_optab, tramp,
  4330.                GEN_INT (TRAMPOLINE_ALIGNMENT - 1),
  4331.                temp, 0, OPTAB_LIB_WIDEN);
  4332.   tramp = expand_binop (Pmode, and_optab, temp,
  4333.             GEN_INT (- TRAMPOLINE_ALIGNMENT),
  4334.             temp, 0, OPTAB_LIB_WIDEN);
  4335. #endif
  4336.   return tramp;
  4337. }
  4338.  
  4339. /* The functions identify_blocks and reorder_blocks provide a way to
  4340.    reorder the tree of BLOCK nodes, for optimizers that reshuffle or
  4341.    duplicate portions of the RTL code.  Call identify_blocks before
  4342.    changing the RTL, and call reorder_blocks after.  */
  4343.  
  4344. /* Put all this function's BLOCK nodes into a vector, and return it.
  4345.    Also store in each NOTE for the beginning or end of a block
  4346.    the index of that block in the vector.
  4347.    The arguments are TOP_BLOCK, the top-level block of the function,
  4348.    and INSNS, the insn chain of the function.  */
  4349.  
  4350. tree *
  4351. identify_blocks (top_block, insns)
  4352.      tree top_block;
  4353.      rtx insns;
  4354. {
  4355.   int n_blocks;
  4356.   tree *block_vector;
  4357.   int *block_stack;
  4358.   int depth = 0;
  4359.   int next_block_number = 0;
  4360.   int current_block_number = 0;
  4361.   rtx insn;
  4362.  
  4363.   if (top_block == 0)
  4364.     return 0;
  4365.  
  4366.   n_blocks = all_blocks (top_block, 0);
  4367.   block_vector = (tree *) xmalloc (n_blocks * sizeof (tree));
  4368.   block_stack = (int *) alloca (n_blocks * sizeof (int));
  4369.  
  4370.   all_blocks (top_block, block_vector);
  4371.  
  4372.   for (insn = insns; insn; insn = NEXT_INSN (insn))
  4373.     if (GET_CODE (insn) == NOTE)
  4374.       {
  4375.     if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG)
  4376.       {
  4377.         block_stack[depth++] = current_block_number;
  4378.         current_block_number = next_block_number;
  4379.         NOTE_BLOCK_NUMBER (insn) =  next_block_number++;
  4380.       }
  4381.     if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END)
  4382.       {
  4383.         current_block_number = block_stack[--depth];
  4384.         NOTE_BLOCK_NUMBER (insn) = current_block_number;
  4385.       }
  4386.       }
  4387.  
  4388.   return block_vector;
  4389. }
  4390.  
  4391. /* Given BLOCK_VECTOR which was returned by identify_blocks,
  4392.    and a revised instruction chain, rebuild the tree structure
  4393.    of BLOCK nodes to correspond to the new order of RTL.
  4394.    The new block tree is inserted below TOP_BLOCK.
  4395.    Returns the current top-level block.  */
  4396.  
  4397. tree
  4398. reorder_blocks (block_vector, top_block, insns)
  4399.      tree *block_vector;
  4400.      tree top_block;
  4401.      rtx insns;
  4402. {
  4403.   tree current_block = top_block;
  4404.   rtx insn;
  4405.  
  4406.   if (block_vector == 0)
  4407.     return top_block;
  4408.  
  4409.   /* Prune the old tree away, so that it doesn't get in the way.  */
  4410.   BLOCK_SUBBLOCKS (current_block) = 0;
  4411.  
  4412.   for (insn = insns; insn; insn = NEXT_INSN (insn))
  4413.     if (GET_CODE (insn) == NOTE)
  4414.       {
  4415.     if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG)
  4416.       {
  4417.         tree block = block_vector[NOTE_BLOCK_NUMBER (insn)];
  4418.         /* If we have seen this block before, copy it.  */
  4419.         if (TREE_ASM_WRITTEN (block))
  4420.           block = copy_node (block);
  4421.         BLOCK_SUBBLOCKS (block) = 0;
  4422.         TREE_ASM_WRITTEN (block) = 1;
  4423.         BLOCK_SUPERCONTEXT (block) = current_block; 
  4424.         BLOCK_CHAIN (block) = BLOCK_SUBBLOCKS (current_block);
  4425.         BLOCK_SUBBLOCKS (current_block) = block;
  4426.         current_block = block;
  4427.         NOTE_SOURCE_FILE (insn) = 0;
  4428.       }
  4429.     if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END)
  4430.       {
  4431.         BLOCK_SUBBLOCKS (current_block)
  4432.           = blocks_nreverse (BLOCK_SUBBLOCKS (current_block));
  4433.         current_block = BLOCK_SUPERCONTEXT (current_block);
  4434.         NOTE_SOURCE_FILE (insn) = 0;
  4435.       }
  4436.       }
  4437.  
  4438.   return current_block;
  4439. }
  4440.  
  4441. /* Reverse the order of elements in the chain T of blocks,
  4442.    and return the new head of the chain (old last element).  */
  4443.  
  4444. static tree
  4445. blocks_nreverse (t)
  4446.      tree t;
  4447. {
  4448.   register tree prev = 0, decl, next;
  4449.   for (decl = t; decl; decl = next)
  4450.     {
  4451.       next = BLOCK_CHAIN (decl);
  4452.       BLOCK_CHAIN (decl) = prev;
  4453.       prev = decl;
  4454.     }
  4455.   return prev;
  4456. }
  4457.  
  4458. /* Count the subblocks of BLOCK, and list them all into the vector VECTOR.
  4459.    Also clear TREE_ASM_WRITTEN in all blocks.  */
  4460.  
  4461. static int
  4462. all_blocks (block, vector)
  4463.      tree block;
  4464.      tree *vector;
  4465. {
  4466.   int n_blocks = 1;
  4467.   tree subblocks; 
  4468.  
  4469.   TREE_ASM_WRITTEN (block) = 0;
  4470.   /* Record this block.  */
  4471.   if (vector)
  4472.     vector[0] = block;
  4473.  
  4474.   /* Record the subblocks, and their subblocks.  */
  4475.   for (subblocks = BLOCK_SUBBLOCKS (block);
  4476.        subblocks; subblocks = BLOCK_CHAIN (subblocks))
  4477.     n_blocks += all_blocks (subblocks, vector ? vector + n_blocks : 0);
  4478.  
  4479.   return n_blocks;
  4480. }
  4481.  
  4482. /* Build bytecode call descriptor for function SUBR. */
  4483.  
  4484. rtx
  4485. bc_build_calldesc (subr)
  4486.   tree subr;
  4487. {
  4488.   tree calldesc = 0, arg;
  4489.   int nargs = 0;
  4490.  
  4491.   /* Build the argument description vector in reverse order.  */
  4492.   DECL_ARGUMENTS (subr) = nreverse (DECL_ARGUMENTS (subr));
  4493.   nargs = 0;
  4494.  
  4495.   for (arg = DECL_ARGUMENTS (subr); arg; arg = TREE_CHAIN (arg))
  4496.     {
  4497.       ++nargs;
  4498.  
  4499.       calldesc = tree_cons ((tree) 0, size_in_bytes (TREE_TYPE (arg)), calldesc);
  4500.       calldesc = tree_cons ((tree) 0, bc_runtime_type_code (TREE_TYPE (arg)), calldesc);
  4501.     }
  4502.  
  4503.   DECL_ARGUMENTS (subr) = nreverse (DECL_ARGUMENTS (subr));
  4504.  
  4505.   /* Prepend the function's return type.  */
  4506.   calldesc = tree_cons ((tree) 0,
  4507.             size_in_bytes (TREE_TYPE (TREE_TYPE (subr))),
  4508.             calldesc);
  4509.  
  4510.   calldesc = tree_cons ((tree) 0,
  4511.             bc_runtime_type_code (TREE_TYPE (TREE_TYPE (subr))),
  4512.             calldesc);
  4513.  
  4514.   /* Prepend the arg count.  */
  4515.   calldesc = tree_cons ((tree) 0, build_int_2 (nargs, 0), calldesc);
  4516.  
  4517.   /* Output the call description vector and get its address.  */
  4518.   calldesc = build_nt (CONSTRUCTOR, (tree) 0, calldesc);
  4519.   TREE_TYPE (calldesc) = build_array_type (integer_type_node,
  4520.                        build_index_type (build_int_2 (nargs * 2, 0)));
  4521.  
  4522.   return output_constant_def (calldesc);
  4523. }
  4524.  
  4525.  
  4526. /* Generate RTL for the start of the function SUBR (a FUNCTION_DECL tree node)
  4527.    and initialize static variables for generating RTL for the statements
  4528.    of the function.  */
  4529.  
  4530. void
  4531. init_function_start (subr, filename, line)
  4532.      tree subr;
  4533.      char *filename;
  4534.      int line;
  4535. {
  4536.   char *junk;
  4537.  
  4538.   if (output_bytecode)
  4539.     {
  4540.       this_function_decl = subr;
  4541.       this_function_calldesc = bc_build_calldesc (subr);
  4542.       local_vars_size = 0;
  4543.       stack_depth = 0;
  4544.       max_stack_depth = 0;
  4545.       stmt_expr_depth = 0;
  4546.       return;
  4547.     }
  4548.  
  4549.   init_stmt_for_function ();
  4550.  
  4551.   cse_not_expected = ! optimize;
  4552.  
  4553.   /* Caller save not needed yet.  */
  4554.   caller_save_needed = 0;
  4555.  
  4556.   /* No stack slots have been made yet.  */
  4557.   stack_slot_list = 0;
  4558.  
  4559.   /* There is no stack slot for handling nonlocal gotos.  */
  4560.   nonlocal_goto_handler_slot = 0;
  4561.   nonlocal_goto_stack_level = 0;
  4562.  
  4563.   /* No labels have been declared for nonlocal use.  */
  4564.   nonlocal_labels = 0;
  4565.  
  4566.   /* No function calls so far in this function.  */
  4567.   function_call_count = 0;
  4568.  
  4569.   /* No parm regs have been allocated.
  4570.      (This is important for output_inline_function.)  */
  4571.   max_parm_reg = LAST_VIRTUAL_REGISTER + 1;
  4572.  
  4573.   /* Initialize the RTL mechanism.  */
  4574.   init_emit ();
  4575.  
  4576.   /* Initialize the queue of pending postincrement and postdecrements,
  4577.      and some other info in expr.c.  */
  4578.   init_expr ();
  4579.  
  4580.   /* We haven't done register allocation yet.  */
  4581.   reg_renumber = 0;
  4582.  
  4583.   init_const_rtx_hash_table ();
  4584.  
  4585.   current_function_name = (*decl_printable_name) (subr, &junk);
  4586.  
  4587.   /* Nonzero if this is a nested function that uses a static chain.  */
  4588.  
  4589.   current_function_needs_context
  4590.     = (decl_function_context (current_function_decl) != 0);
  4591.  
  4592.   /* Set if a call to setjmp is seen.  */
  4593.   current_function_calls_setjmp = 0;
  4594.  
  4595.   /* Set if a call to longjmp is seen.  */
  4596.   current_function_calls_longjmp = 0;
  4597.  
  4598.   current_function_calls_alloca = 0;
  4599.   current_function_has_nonlocal_label = 0;
  4600.   current_function_has_nonlocal_goto = 0;
  4601.   current_function_contains_functions = 0;
  4602.  
  4603.   current_function_returns_pcc_struct = 0;
  4604.   current_function_returns_struct = 0;
  4605.   current_function_epilogue_delay_list = 0;
  4606.   current_function_uses_const_pool = 0;
  4607.   current_function_uses_pic_offset_table = 0;
  4608.  
  4609.   /* We have not yet needed to make a label to jump to for tail-recursion.  */
  4610.   tail_recursion_label = 0;
  4611.  
  4612.   /* We haven't had a need to make a save area for ap yet.  */
  4613.  
  4614.   arg_pointer_save_area = 0;
  4615.  
  4616.   /* No stack slots allocated yet.  */
  4617.   frame_offset = 0;
  4618.  
  4619.   /* No SAVE_EXPRs in this function yet.  */
  4620.   save_expr_regs = 0;
  4621.  
  4622.   /* No RTL_EXPRs in this function yet.  */
  4623.   rtl_expr_chain = 0;
  4624.  
  4625.   /* We have not allocated any temporaries yet.  */
  4626.   temp_slots = 0;
  4627.   temp_slot_level = 0;
  4628.   target_temp_slot_level = 0;
  4629.  
  4630.   /* Within function body, compute a type's size as soon it is laid out.  */
  4631.   immediate_size_expand++;
  4632.  
  4633.   /* We haven't made any trampolines for this function yet.  */
  4634.   trampoline_list = 0;
  4635.  
  4636.   init_pending_stack_adjust ();
  4637.   inhibit_defer_pop = 0;
  4638.  
  4639.   current_function_outgoing_args_size = 0;
  4640.  
  4641.   /* Initialize the insn lengths.  */
  4642.   init_insn_lengths ();
  4643.  
  4644.   /* Prevent ever trying to delete the first instruction of a function.
  4645.      Also tell final how to output a linenum before the function prologue.  */
  4646.   emit_line_note (filename, line);
  4647.  
  4648.   /* Make sure first insn is a note even if we don't want linenums.
  4649.      This makes sure the first insn will never be deleted.
  4650.      Also, final expects a note to appear there.  */
  4651.   emit_note (NULL_PTR, NOTE_INSN_DELETED);
  4652.  
  4653.   /* Set flags used by final.c.  */
  4654.   if (aggregate_value_p (DECL_RESULT (subr)))
  4655.     {
  4656. #ifdef PCC_STATIC_STRUCT_RETURN
  4657.       current_function_returns_pcc_struct = 1;
  4658. #endif
  4659.       current_function_returns_struct = 1;
  4660.     }
  4661.  
  4662.   /* Warn if this value is an aggregate type,
  4663.      regardless of which calling convention we are using for it.  */
  4664.   if (warn_aggregate_return
  4665.       && AGGREGATE_TYPE_P (TREE_TYPE (DECL_RESULT (subr))))
  4666.     warning ("function returns an aggregate");
  4667.  
  4668.   current_function_returns_pointer
  4669.     = (TREE_CODE (TREE_TYPE (DECL_RESULT (subr))) == POINTER_TYPE);
  4670.  
  4671.   /* Indicate that we need to distinguish between the return value of the
  4672.      present function and the return value of a function being called.  */
  4673.   rtx_equal_function_value_matters = 1;
  4674.  
  4675.   /* Indicate that we have not instantiated virtual registers yet.  */
  4676.   virtuals_instantiated = 0;
  4677.  
  4678.   /* Indicate we have no need of a frame pointer yet.  */
  4679.   frame_pointer_needed = 0;
  4680.  
  4681.   /* By default assume not varargs.  */
  4682.   current_function_varargs = 0;
  4683. }
  4684.  
  4685. /* Indicate that the current function uses extra args
  4686.    not explicitly mentioned in the argument list in any fashion.  */
  4687.  
  4688. void
  4689. mark_varargs ()
  4690. {
  4691.   current_function_varargs = 1;
  4692. }
  4693.  
  4694. /* Expand a call to __main at the beginning of a possible main function.  */
  4695.  
  4696. void
  4697. expand_main_function ()
  4698. {
  4699.   if (!output_bytecode)
  4700.     {
  4701.       /* The zero below avoids a possible parse error */
  4702.       0;
  4703. #if !defined (INIT_SECTION_ASM_OP) || defined (INVOKE__main)
  4704.       emit_library_call (gen_rtx (SYMBOL_REF, Pmode, NAME__MAIN), 0,
  4705.              VOIDmode, 0);
  4706. #endif /* not INIT_SECTION_ASM_OP or INVOKE__main */
  4707.     }
  4708. }
  4709.  
  4710. extern struct obstack permanent_obstack;
  4711.  
  4712. /* Expand start of bytecode function. See comment at
  4713.    expand_function_start below for details. */
  4714.  
  4715. void
  4716. bc_expand_function_start (subr, parms_have_cleanups)
  4717.   tree subr;
  4718.   int parms_have_cleanups;
  4719. {
  4720.   char label[20], *name;
  4721.   static int nlab;
  4722.   tree thisarg;
  4723.   int argsz;
  4724.  
  4725.   if (TREE_PUBLIC (subr))
  4726.     bc_globalize_label (IDENTIFIER_POINTER (DECL_NAME (subr)));
  4727.  
  4728. #ifdef DEBUG_PRINT_CODE
  4729.   fprintf (stderr, "\n<func %s>\n", IDENTIFIER_POINTER (DECL_NAME (subr)));
  4730. #endif
  4731.  
  4732.   for (argsz = 0, thisarg = DECL_ARGUMENTS (subr); thisarg; thisarg = TREE_CHAIN (thisarg))
  4733.     {
  4734.       if (DECL_RTL (thisarg))
  4735.     abort ();        /* Should be NULL here I think.  */
  4736.       else if (TREE_CONSTANT (DECL_SIZE (thisarg)))
  4737.     {
  4738.       DECL_RTL (thisarg) = bc_gen_rtx ((char *) 0, argsz, (struct bc_label *) 0);
  4739.       argsz += TREE_INT_CST_LOW (DECL_SIZE (thisarg));
  4740.     }
  4741.       else
  4742.     {
  4743.       /* Variable-sized objects are pointers to their storage. */
  4744.       DECL_RTL (thisarg) = bc_gen_rtx ((char *) 0, argsz, (struct bc_label *) 0);
  4745.       argsz += POINTER_SIZE;
  4746.     }
  4747.     }
  4748.  
  4749.   bc_begin_function (bc_xstrdup (IDENTIFIER_POINTER (DECL_NAME (subr))));
  4750.  
  4751.   ASM_GENERATE_INTERNAL_LABEL (label, "LX", nlab);
  4752.  
  4753.   ++nlab;
  4754.   name = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label));
  4755.   this_function_callinfo = bc_gen_rtx (name, 0, (struct bc_label *) 0);
  4756.   this_function_bytecode =
  4757.     bc_emit_trampoline (BYTECODE_LABEL (this_function_callinfo));
  4758. }
  4759.  
  4760.  
  4761. /* Expand end of bytecode function. See details the comment of
  4762.    expand_function_end(), below. */
  4763.  
  4764. void
  4765. bc_expand_function_end ()
  4766. {
  4767.   char *ptrconsts;
  4768.  
  4769.   expand_null_return ();
  4770.  
  4771.   /* Emit any fixup code. This must be done before the call to
  4772.      to BC_END_FUNCTION (), since that will cause the bytecode
  4773.      segment to be finished off and closed. */
  4774.  
  4775.   expand_fixups (NULL_RTX);
  4776.  
  4777.   ptrconsts = bc_end_function ();
  4778.  
  4779.   bc_align_const (2 /* INT_ALIGN */);
  4780.  
  4781.   /* If this changes also make sure to change bc-interp.h!  */
  4782.  
  4783.   bc_emit_const_labeldef (BYTECODE_LABEL (this_function_callinfo));
  4784.   bc_emit_const ((char *) &max_stack_depth, sizeof max_stack_depth);
  4785.   bc_emit_const ((char *) &local_vars_size, sizeof local_vars_size);
  4786.   bc_emit_const_labelref (this_function_bytecode, 0);
  4787.   bc_emit_const_labelref (ptrconsts, 0);
  4788.   bc_emit_const_labelref (BYTECODE_LABEL (this_function_calldesc), 0);
  4789. }
  4790.  
  4791.  
  4792. /* Start the RTL for a new function, and set variables used for
  4793.    emitting RTL.
  4794.    SUBR is the FUNCTION_DECL node.
  4795.    PARMS_HAVE_CLEANUPS is nonzero if there are cleanups associated with
  4796.    the function's parameters, which must be run at any return statement.  */
  4797.  
  4798. void
  4799. expand_function_start (subr, parms_have_cleanups)
  4800.      tree subr;
  4801.      int parms_have_cleanups;
  4802. {
  4803.   register int i;
  4804.   tree tem;
  4805.   rtx last_ptr;
  4806.  
  4807.   if (output_bytecode)
  4808.     {
  4809.       bc_expand_function_start (subr, parms_have_cleanups);
  4810.       return;
  4811.     }
  4812.  
  4813.   /* Make sure volatile mem refs aren't considered
  4814.      valid operands of arithmetic insns.  */
  4815.   init_recog_no_volatile ();
  4816.  
  4817.   /* If function gets a static chain arg, store it in the stack frame.
  4818.      Do this first, so it gets the first stack slot offset.  */
  4819.   if (current_function_needs_context)
  4820.     {
  4821.       last_ptr = assign_stack_local (Pmode, GET_MODE_SIZE (Pmode), 0);
  4822.  
  4823. #ifdef SMALL_REGISTER_CLASSES
  4824.       /* Delay copying static chain if it is not a register to avoid
  4825.      conflicts with regs used for parameters.  */
  4826.       if (GET_CODE (static_chain_incoming_rtx) == REG)
  4827. #endif
  4828.         emit_move_insn (last_ptr, static_chain_incoming_rtx);
  4829.     }
  4830.  
  4831.   /* If the parameters of this function need cleaning up, get a label
  4832.      for the beginning of the code which executes those cleanups.  This must
  4833.      be done before doing anything with return_label.  */
  4834.   if (parms_have_cleanups)
  4835.     cleanup_label = gen_label_rtx ();
  4836.   else
  4837.     cleanup_label = 0;
  4838.  
  4839.   /* Make the label for return statements to jump to, if this machine
  4840.      does not have a one-instruction return and uses an epilogue,
  4841.      or if it returns a structure, or if it has parm cleanups.  */
  4842. #ifdef HAVE_return
  4843.   if (cleanup_label == 0 && HAVE_return
  4844.       && ! current_function_returns_pcc_struct
  4845.       && ! (current_function_returns_struct && ! optimize))
  4846.     return_label = 0;
  4847.   else
  4848.     return_label = gen_label_rtx ();
  4849. #else
  4850.   return_label = gen_label_rtx ();
  4851. #endif
  4852.  
  4853.   /* Initialize rtx used to return the value.  */
  4854.   /* Do this before assign_parms so that we copy the struct value address
  4855.      before any library calls that assign parms might generate.  */
  4856.  
  4857.   /* Decide whether to return the value in memory or in a register.  */
  4858.   if (aggregate_value_p (DECL_RESULT (subr)))
  4859.     {
  4860.       /* Returning something that won't go in a register.  */
  4861.       register rtx value_address;
  4862.  
  4863. #ifdef PCC_STATIC_STRUCT_RETURN
  4864.       if (current_function_returns_pcc_struct)
  4865.     {
  4866.       int size = int_size_in_bytes (TREE_TYPE (DECL_RESULT (subr)));
  4867.       value_address = assemble_static_space (size);
  4868.     }
  4869.       else
  4870. #endif
  4871.     {
  4872.       /* Expect to be passed the address of a place to store the value.
  4873.          If it is passed as an argument, assign_parms will take care of
  4874.          it.  */
  4875.       if (struct_value_incoming_rtx)
  4876.         {
  4877.           value_address = gen_reg_rtx (Pmode);
  4878.           emit_move_insn (value_address, struct_value_incoming_rtx);
  4879.         }
  4880.     }
  4881.       if (value_address)
  4882.     {
  4883.       DECL_RTL (DECL_RESULT (subr))
  4884.         = gen_rtx (MEM, DECL_MODE (DECL_RESULT (subr)), value_address);
  4885.       MEM_IN_STRUCT_P (DECL_RTL (DECL_RESULT (subr)))
  4886.         = AGGREGATE_TYPE_P (TREE_TYPE (DECL_RESULT (subr)));
  4887.     }
  4888.     }
  4889.   else if (DECL_MODE (DECL_RESULT (subr)) == VOIDmode)
  4890.     /* If return mode is void, this decl rtl should not be used.  */
  4891.     DECL_RTL (DECL_RESULT (subr)) = 0;
  4892.   else if (parms_have_cleanups)
  4893.     {
  4894.       /* If function will end with cleanup code for parms,
  4895.      compute the return values into a pseudo reg,
  4896.      which we will copy into the true return register
  4897.      after the cleanups are done.  */
  4898.  
  4899.       enum machine_mode mode = DECL_MODE (DECL_RESULT (subr));
  4900.  
  4901. #ifdef PROMOTE_FUNCTION_RETURN
  4902.       tree type = TREE_TYPE (DECL_RESULT (subr));
  4903.       int unsignedp = TREE_UNSIGNED (type);
  4904.  
  4905.       mode = promote_mode (type, mode, &unsignedp, 1);
  4906. #endif
  4907.  
  4908.       DECL_RTL (DECL_RESULT (subr)) = gen_reg_rtx (mode);
  4909.     }
  4910.   else
  4911.     /* Scalar, returned in a register.  */
  4912.     {
  4913. #ifdef FUNCTION_OUTGOING_VALUE
  4914.       DECL_RTL (DECL_RESULT (subr))
  4915.     = FUNCTION_OUTGOING_VALUE (TREE_TYPE (DECL_RESULT (subr)), subr);
  4916. #else
  4917.       DECL_RTL (DECL_RESULT (subr))
  4918.     = FUNCTION_VALUE (TREE_TYPE (DECL_RESULT (subr)), subr);
  4919. #endif
  4920.  
  4921.       /* Mark this reg as the function's return value.  */
  4922.       if (GET_CODE (DECL_RTL (DECL_RESULT (subr))) == REG)
  4923.     {
  4924.       REG_FUNCTION_VALUE_P (DECL_RTL (DECL_RESULT (subr))) = 1;
  4925.       /* Needed because we may need to move this to memory
  4926.          in case it's a named return value whose address is taken.  */
  4927.       DECL_REGISTER (DECL_RESULT (subr)) = 1;
  4928.     }
  4929.     }
  4930.  
  4931.   /* Initialize rtx for parameters and local variables.
  4932.      In some cases this requires emitting insns.  */
  4933.  
  4934.   assign_parms (subr, 0);
  4935.  
  4936. #ifdef SMALL_REGISTER_CLASSES
  4937.   /* Copy the static chain now if it wasn't a register.  The delay is to
  4938.      avoid conflicts with the parameter passing registers.  */
  4939.  
  4940.   if (current_function_needs_context)
  4941.       if (GET_CODE (static_chain_incoming_rtx) != REG)
  4942.         emit_move_insn (last_ptr, static_chain_incoming_rtx);
  4943. #endif
  4944.  
  4945.   /* The following was moved from init_function_start.
  4946.      The move is supposed to make sdb output more accurate.  */
  4947.   /* Indicate the beginning of the function body,
  4948.      as opposed to parm setup.  */
  4949.   emit_note (NULL_PTR, NOTE_INSN_FUNCTION_BEG);
  4950.  
  4951.   /* If doing stupid allocation, mark parms as born here.  */
  4952.  
  4953.   if (GET_CODE (get_last_insn ()) != NOTE)
  4954.     emit_note (NULL_PTR, NOTE_INSN_DELETED);
  4955.   parm_birth_insn = get_last_insn ();
  4956.  
  4957.   if (obey_regdecls)
  4958.     {
  4959.       for (i = LAST_VIRTUAL_REGISTER + 1; i < max_parm_reg; i++)
  4960.     use_variable (regno_reg_rtx[i]);
  4961.  
  4962.       if (current_function_internal_arg_pointer != virtual_incoming_args_rtx)
  4963.     use_variable (current_function_internal_arg_pointer);
  4964.     }
  4965.  
  4966.   /* Fetch static chain values for containing functions.  */
  4967.   tem = decl_function_context (current_function_decl);
  4968.   /* If not doing stupid register allocation, then start off with the static
  4969.      chain pointer in a pseudo register.  Otherwise, we use the stack
  4970.      address that was generated above.  */
  4971.   if (tem && ! obey_regdecls)
  4972.     last_ptr = copy_to_reg (static_chain_incoming_rtx);
  4973.   context_display = 0;
  4974.   while (tem)
  4975.     {
  4976.       tree rtlexp = make_node (RTL_EXPR);
  4977.  
  4978.       RTL_EXPR_RTL (rtlexp) = last_ptr;
  4979.       context_display = tree_cons (tem, rtlexp, context_display);
  4980.       tem = decl_function_context (tem);
  4981.       if (tem == 0)
  4982.     break;
  4983.       /* Chain thru stack frames, assuming pointer to next lexical frame
  4984.      is found at the place we always store it.  */
  4985. #ifdef FRAME_GROWS_DOWNWARD
  4986.       last_ptr = plus_constant (last_ptr, - GET_MODE_SIZE (Pmode));
  4987. #endif
  4988.       last_ptr = copy_to_reg (gen_rtx (MEM, Pmode,
  4989.                        memory_address (Pmode, last_ptr)));
  4990.  
  4991.       /* If we are not optimizing, ensure that we know that this
  4992.      piece of context is live over the entire function.  */
  4993.       if (! optimize)
  4994.     save_expr_regs = gen_rtx (EXPR_LIST, VOIDmode, last_ptr,
  4995.                   save_expr_regs);
  4996.     }
  4997.  
  4998.   /* After the display initializations is where the tail-recursion label
  4999.      should go, if we end up needing one.   Ensure we have a NOTE here
  5000.      since some things (like trampolines) get placed before this.  */
  5001.   tail_recursion_reentry = emit_note (NULL_PTR, NOTE_INSN_DELETED);
  5002.  
  5003.   /* Evaluate now the sizes of any types declared among the arguments.  */
  5004.   for (tem = nreverse (get_pending_sizes ()); tem; tem = TREE_CHAIN (tem))
  5005.     expand_expr (TREE_VALUE (tem), const0_rtx, VOIDmode, 0);
  5006.  
  5007.   /* Make sure there is a line number after the function entry setup code.  */
  5008.   force_next_line_note ();
  5009. }
  5010.  
  5011. /* Generate RTL for the end of the current function.
  5012.    FILENAME and LINE are the current position in the source file. 
  5013.  
  5014.    It is up to language-specific callers to do cleanups for parameters--
  5015.    or else, supply 1 for END_BINDINGS and we will call expand_end_bindings.  */
  5016.  
  5017. void
  5018. expand_function_end (filename, line, end_bindings)
  5019.      char *filename;
  5020.      int line;
  5021.      int end_bindings;
  5022. {
  5023.   register int i;
  5024.   tree link;
  5025.  
  5026.   static rtx initial_trampoline;
  5027.  
  5028.   if (output_bytecode)
  5029.     {
  5030.       bc_expand_function_end ();
  5031.       return;
  5032.     }
  5033.  
  5034. #ifdef NON_SAVING_SETJMP
  5035.   /* Don't put any variables in registers if we call setjmp
  5036.      on a machine that fails to restore the registers.  */
  5037.   if (NON_SAVING_SETJMP && current_function_calls_setjmp)
  5038.     {
  5039.       setjmp_protect (DECL_INITIAL (current_function_decl));
  5040.       setjmp_protect_args ();
  5041.     }
  5042. #endif
  5043.  
  5044.   /* Save the argument pointer if a save area was made for it.  */
  5045.   if (arg_pointer_save_area)
  5046.     {
  5047.       rtx x = gen_move_insn (arg_pointer_save_area, virtual_incoming_args_rtx);
  5048.       emit_insn_before (x, tail_recursion_reentry);
  5049.     }
  5050.  
  5051.   /* Initialize any trampolines required by this function.  */
  5052.   for (link = trampoline_list; link; link = TREE_CHAIN (link))
  5053.     {
  5054.       tree function = TREE_PURPOSE (link);
  5055.       rtx context = lookup_static_chain (function);
  5056.       rtx tramp = RTL_EXPR_RTL (TREE_VALUE (link));
  5057.       rtx seq;
  5058.  
  5059.       /* First make sure this compilation has a template for
  5060.      initializing trampolines.  */
  5061.       if (initial_trampoline == 0)
  5062.     {
  5063.       end_temporary_allocation ();
  5064.       initial_trampoline
  5065.         = gen_rtx (MEM, BLKmode, assemble_trampoline_template ());
  5066.       resume_temporary_allocation ();
  5067.     }
  5068.  
  5069.       /* Generate insns to initialize the trampoline.  */
  5070.       start_sequence ();
  5071.       tramp = change_address (initial_trampoline, BLKmode,
  5072.                   round_trampoline_addr (XEXP (tramp, 0)));
  5073.       emit_block_move (tramp, initial_trampoline, GEN_INT (TRAMPOLINE_SIZE),
  5074.                FUNCTION_BOUNDARY / BITS_PER_UNIT);
  5075.       INITIALIZE_TRAMPOLINE (XEXP (tramp, 0),
  5076.                  XEXP (DECL_RTL (function), 0), context);
  5077.       seq = get_insns ();
  5078.       end_sequence ();
  5079.  
  5080.       /* Put those insns at entry to the containing function (this one).  */
  5081.       emit_insns_before (seq, tail_recursion_reentry);
  5082.     }
  5083.  
  5084. #if 0  /* I think unused parms are legitimate enough.  */
  5085.   /* Warn about unused parms.  */
  5086.   if (warn_unused)
  5087.     {
  5088.       rtx decl;
  5089.  
  5090.       for (decl = DECL_ARGUMENTS (current_function_decl);
  5091.        decl; decl = TREE_CHAIN (decl))
  5092.     if (! TREE_USED (decl) && TREE_CODE (decl) == VAR_DECL)
  5093.       warning_with_decl (decl, "unused parameter `%s'");
  5094.     }
  5095. #endif
  5096.  
  5097.   /* Delete handlers for nonlocal gotos if nothing uses them.  */
  5098.   if (nonlocal_goto_handler_slot != 0 && !current_function_has_nonlocal_label)
  5099.     delete_handlers ();
  5100.  
  5101.   /* End any sequences that failed to be closed due to syntax errors.  */
  5102.   while (in_sequence_p ())
  5103.     end_sequence ();
  5104.  
  5105.   /* Outside function body, can't compute type's actual size
  5106.      until next function's body starts.  */
  5107.   immediate_size_expand--;
  5108.  
  5109.   /* If doing stupid register allocation,
  5110.      mark register parms as dying here.  */
  5111.  
  5112.   if (obey_regdecls)
  5113.     {
  5114.       rtx tem;
  5115.       for (i = LAST_VIRTUAL_REGISTER + 1; i < max_parm_reg; i++)
  5116.     use_variable (regno_reg_rtx[i]);
  5117.  
  5118.       /* Likewise for the regs of all the SAVE_EXPRs in the function.  */
  5119.  
  5120.       for (tem = save_expr_regs; tem; tem = XEXP (tem, 1))
  5121.     {
  5122.       use_variable (XEXP (tem, 0));
  5123.       use_variable_after (XEXP (tem, 0), parm_birth_insn);
  5124.     }
  5125.  
  5126.       if (current_function_internal_arg_pointer != virtual_incoming_args_rtx)
  5127.     use_variable (current_function_internal_arg_pointer);
  5128.     }
  5129.  
  5130.   clear_pending_stack_adjust ();
  5131.   do_pending_stack_adjust ();
  5132.  
  5133.   /* Mark the end of the function body.
  5134.      If control reaches this insn, the function can drop through
  5135.      without returning a value.  */
  5136.   emit_note (NULL_PTR, NOTE_INSN_FUNCTION_END);
  5137.  
  5138.   /* Output a linenumber for the end of the function.
  5139.      SDB depends on this.  */
  5140.   emit_line_note_force (filename, line);
  5141.  
  5142.   /* Output the label for the actual return from the function,
  5143.      if one is expected.  This happens either because a function epilogue
  5144.      is used instead of a return instruction, or because a return was done
  5145.      with a goto in order to run local cleanups, or because of pcc-style
  5146.      structure returning.  */
  5147.  
  5148.   if (return_label)
  5149.     emit_label (return_label);
  5150.  
  5151.   /* C++ uses this.  */
  5152.   if (end_bindings)
  5153.     expand_end_bindings (0, 0, 0);
  5154.  
  5155.   /* If we had calls to alloca, and this machine needs
  5156.      an accurate stack pointer to exit the function,
  5157.      insert some code to save and restore the stack pointer.  */
  5158. #ifdef EXIT_IGNORE_STACK
  5159.   if (! EXIT_IGNORE_STACK)
  5160. #endif
  5161.     if (current_function_calls_alloca)
  5162.       {
  5163.     rtx tem = 0;
  5164.  
  5165.     emit_stack_save (SAVE_FUNCTION, &tem, parm_birth_insn);
  5166.     emit_stack_restore (SAVE_FUNCTION, tem, NULL_RTX);
  5167.       }
  5168.  
  5169.   /* If scalar return value was computed in a pseudo-reg,
  5170.      copy that to the hard return register.  */
  5171.   if (DECL_RTL (DECL_RESULT (current_function_decl)) != 0
  5172.       && GET_CODE (DECL_RTL (DECL_RESULT (current_function_decl))) == REG
  5173.       && (REGNO (DECL_RTL (DECL_RESULT (current_function_decl)))
  5174.       >= FIRST_PSEUDO_REGISTER))
  5175.     {
  5176.       rtx real_decl_result;
  5177.  
  5178. #ifdef FUNCTION_OUTGOING_VALUE
  5179.       real_decl_result
  5180.     = FUNCTION_OUTGOING_VALUE (TREE_TYPE (DECL_RESULT (current_function_decl)),
  5181.                    current_function_decl);
  5182. #else
  5183.       real_decl_result
  5184.     = FUNCTION_VALUE (TREE_TYPE (DECL_RESULT (current_function_decl)),
  5185.               current_function_decl);
  5186. #endif
  5187.       REG_FUNCTION_VALUE_P (real_decl_result) = 1;
  5188.       emit_move_insn (real_decl_result,
  5189.               DECL_RTL (DECL_RESULT (current_function_decl)));
  5190.       emit_insn (gen_rtx (USE, VOIDmode, real_decl_result));
  5191.     }
  5192.  
  5193.   /* If returning a structure, arrange to return the address of the value
  5194.      in a place where debuggers expect to find it.
  5195.  
  5196.      If returning a structure PCC style,
  5197.      the caller also depends on this value.
  5198.      And current_function_returns_pcc_struct is not necessarily set.  */
  5199.   if (current_function_returns_struct
  5200.       || current_function_returns_pcc_struct)
  5201.     {
  5202.       rtx value_address = XEXP (DECL_RTL (DECL_RESULT (current_function_decl)), 0);
  5203.       tree type = TREE_TYPE (DECL_RESULT (current_function_decl));
  5204. #ifdef FUNCTION_OUTGOING_VALUE
  5205.       rtx outgoing
  5206.     = FUNCTION_OUTGOING_VALUE (build_pointer_type (type),
  5207.                    current_function_decl);
  5208. #else
  5209.       rtx outgoing
  5210.     = FUNCTION_VALUE (build_pointer_type (type),
  5211.               current_function_decl);
  5212. #endif
  5213.  
  5214.       /* Mark this as a function return value so integrate will delete the
  5215.      assignment and USE below when inlining this function.  */
  5216.       REG_FUNCTION_VALUE_P (outgoing) = 1;
  5217.  
  5218.       emit_move_insn (outgoing, value_address);
  5219.       use_variable (outgoing);
  5220.     }
  5221.  
  5222.   /* Output a return insn if we are using one.
  5223.      Otherwise, let the rtl chain end here, to drop through
  5224.      into the epilogue.  */
  5225.  
  5226. #ifdef HAVE_return
  5227.   if (HAVE_return)
  5228.     {
  5229.       emit_jump_insn (gen_return ());
  5230.       emit_barrier ();
  5231.     }
  5232. #endif
  5233.  
  5234.   /* Fix up any gotos that jumped out to the outermost
  5235.      binding level of the function.
  5236.      Must follow emitting RETURN_LABEL.  */
  5237.  
  5238.   /* If you have any cleanups to do at this point,
  5239.      and they need to create temporary variables,
  5240.      then you will lose.  */
  5241.   expand_fixups (get_insns ());
  5242. }
  5243.  
  5244. /* These arrays record the INSN_UIDs of the prologue and epilogue insns.  */
  5245.  
  5246. static int *prologue;
  5247. static int *epilogue;
  5248.  
  5249. /* Create an array that records the INSN_UIDs of INSNS (either a sequence
  5250.    or a single insn).  */
  5251.  
  5252. static int *
  5253. record_insns (insns)
  5254.      rtx insns;
  5255. {
  5256.   int *vec;
  5257.  
  5258.   if (GET_CODE (insns) == SEQUENCE)
  5259.     {
  5260.       int len = XVECLEN (insns, 0);
  5261.       vec = (int *) oballoc ((len + 1) * sizeof (int));
  5262.       vec[len] = 0;
  5263.       while (--len >= 0)
  5264.     vec[len] = INSN_UID (XVECEXP (insns, 0, len));
  5265.     }
  5266.   else
  5267.     {
  5268.       vec = (int *) oballoc (2 * sizeof (int));
  5269.       vec[0] = INSN_UID (insns);
  5270.       vec[1] = 0;
  5271.     }
  5272.   return vec;
  5273. }
  5274.  
  5275. /* Determine how many INSN_UIDs in VEC are part of INSN.  */
  5276.  
  5277. static int
  5278. contains (insn, vec)
  5279.      rtx insn;
  5280.      int *vec;
  5281. {
  5282.   register int i, j;
  5283.  
  5284.   if (GET_CODE (insn) == INSN
  5285.       && GET_CODE (PATTERN (insn)) == SEQUENCE)
  5286.     {
  5287.       int count = 0;
  5288.       for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
  5289.     for (j = 0; vec[j]; j++)
  5290.       if (INSN_UID (XVECEXP (PATTERN (insn), 0, i)) == vec[j])
  5291.         count++;
  5292.       return count;
  5293.     }
  5294.   else
  5295.     {
  5296.       for (j = 0; vec[j]; j++)
  5297.     if (INSN_UID (insn) == vec[j])
  5298.       return 1;
  5299.     }
  5300.   return 0;
  5301. }
  5302.  
  5303. /* Generate the prologe and epilogue RTL if the machine supports it.  Thread
  5304.    this into place with notes indicating where the prologue ends and where
  5305.    the epilogue begins.  Update the basic block information when possible.  */
  5306.  
  5307. void
  5308. thread_prologue_and_epilogue_insns (f)
  5309.      rtx f;
  5310. {
  5311. #ifdef HAVE_prologue
  5312.   if (HAVE_prologue)
  5313.     {
  5314.       rtx head, seq, insn;
  5315.  
  5316.       /* The first insn (a NOTE_INSN_DELETED) is followed by zero or more
  5317.      prologue insns and a NOTE_INSN_PROLOGUE_END.  */
  5318.       emit_note_after (NOTE_INSN_PROLOGUE_END, f);
  5319.       seq = gen_prologue ();
  5320.       head = emit_insn_after (seq, f);
  5321.  
  5322.       /* Include the new prologue insns in the first block.  Ignore them
  5323.      if they form a basic block unto themselves.  */
  5324.       if (basic_block_head && n_basic_blocks
  5325.       && GET_CODE (basic_block_head[0]) != CODE_LABEL)
  5326.     basic_block_head[0] = NEXT_INSN (f);
  5327.  
  5328.       /* Retain a map of the prologue insns.  */
  5329.       prologue = record_insns (GET_CODE (seq) == SEQUENCE ? seq : head);
  5330.     }
  5331.   else
  5332. #endif
  5333.     prologue = 0;
  5334.  
  5335. #ifdef HAVE_epilogue
  5336.   if (HAVE_epilogue)
  5337.     {
  5338.       rtx insn = get_last_insn ();
  5339.       rtx prev = prev_nonnote_insn (insn);
  5340.  
  5341.       /* If we end with a BARRIER, we don't need an epilogue.  */
  5342.       if (! (prev && GET_CODE (prev) == BARRIER))
  5343.     {
  5344.       rtx tail, seq, tem;
  5345.       rtx first_use = 0;
  5346.       rtx last_use = 0;
  5347.  
  5348.       /* The last basic block ends with a NOTE_INSN_EPILOGUE_BEG, the
  5349.          epilogue insns, the USE insns at the end of a function,
  5350.          the jump insn that returns, and then a BARRIER.  */
  5351.  
  5352.       /* Move the USE insns at the end of a function onto a list.  */
  5353.       while (prev
  5354.          && GET_CODE (prev) == INSN
  5355.          && GET_CODE (PATTERN (prev)) == USE)
  5356.         {
  5357.           tem = prev;
  5358.           prev = prev_nonnote_insn (prev);
  5359.  
  5360.           NEXT_INSN (PREV_INSN (tem)) = NEXT_INSN (tem);
  5361.           PREV_INSN (NEXT_INSN (tem)) = PREV_INSN (tem);
  5362.           if (first_use)
  5363.         {
  5364.           NEXT_INSN (tem) = first_use;
  5365.           PREV_INSN (first_use) = tem;
  5366.         }
  5367.           first_use = tem;
  5368.           if (!last_use)
  5369.         last_use = tem;
  5370.         }
  5371.  
  5372.       emit_barrier_after (insn);
  5373.  
  5374.       seq = gen_epilogue ();
  5375.       tail = emit_jump_insn_after (seq, insn);
  5376.  
  5377.       /* Insert the USE insns immediately before the return insn, which
  5378.          must be the first instruction before the final barrier.  */
  5379.       if (first_use)
  5380.         {
  5381.           tem = prev_nonnote_insn (get_last_insn ());
  5382.           NEXT_INSN (PREV_INSN (tem)) = first_use;
  5383.           PREV_INSN (first_use) = PREV_INSN (tem);
  5384.           PREV_INSN (tem) = last_use;
  5385.           NEXT_INSN (last_use) = tem;
  5386.         }
  5387.  
  5388.       emit_note_after (NOTE_INSN_EPILOGUE_BEG, insn);
  5389.  
  5390.       /* Include the new epilogue insns in the last block.  Ignore
  5391.          them if they form a basic block unto themselves.  */
  5392.       if (basic_block_end && n_basic_blocks
  5393.           && GET_CODE (basic_block_end[n_basic_blocks - 1]) != JUMP_INSN)
  5394.         basic_block_end[n_basic_blocks - 1] = tail;
  5395.  
  5396.       /* Retain a map of the epilogue insns.  */
  5397.       epilogue = record_insns (GET_CODE (seq) == SEQUENCE ? seq : tail);
  5398.       return;
  5399.     }
  5400.     }
  5401. #endif
  5402.   epilogue = 0;
  5403. }
  5404.  
  5405. /* Reposition the prologue-end and epilogue-begin notes after instruction
  5406.    scheduling and delayed branch scheduling.  */
  5407.  
  5408. void
  5409. reposition_prologue_and_epilogue_notes (f)
  5410.      rtx f;
  5411. {
  5412. #if defined (HAVE_prologue) || defined (HAVE_epilogue)
  5413.   /* Reposition the prologue and epilogue notes.  */
  5414.   if (n_basic_blocks)
  5415.     {
  5416.       rtx next, prev;
  5417.       int len;
  5418.  
  5419.       if (prologue)
  5420.     {
  5421.       register rtx insn, note = 0;
  5422.  
  5423.       /* Scan from the beginning until we reach the last prologue insn.
  5424.          We apparently can't depend on basic_block_{head,end} after
  5425.          reorg has run.  */
  5426.       for (len = 0; prologue[len]; len++)
  5427.         ;
  5428.       for (insn = f; len && insn; insn = NEXT_INSN (insn))
  5429.         {
  5430.           if (GET_CODE (insn) == NOTE)
  5431.         {
  5432.           if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_PROLOGUE_END)
  5433.             note = insn;
  5434.         }
  5435.           else if ((len -= contains (insn, prologue)) == 0)
  5436.         {
  5437.           /* Find the prologue-end note if we haven't already, and
  5438.              move it to just after the last prologue insn.  */
  5439.           if (note == 0)
  5440.             {
  5441.               for (note = insn; note = NEXT_INSN (note);)
  5442.             if (GET_CODE (note) == NOTE
  5443.                 && NOTE_LINE_NUMBER (note) == NOTE_INSN_PROLOGUE_END)
  5444.               break;
  5445.             }
  5446.           next = NEXT_INSN (note);
  5447.           prev = PREV_INSN (note);
  5448.           if (prev)
  5449.             NEXT_INSN (prev) = next;
  5450.           if (next)
  5451.             PREV_INSN (next) = prev;
  5452.           add_insn_after (note, insn);
  5453.         }
  5454.         }
  5455.     }
  5456.  
  5457.       if (epilogue)
  5458.     {
  5459.       register rtx insn, note = 0;
  5460.  
  5461.       /* Scan from the end until we reach the first epilogue insn.
  5462.          We apparently can't depend on basic_block_{head,end} after
  5463.          reorg has run.  */
  5464.       for (len = 0; epilogue[len]; len++)
  5465.         ;
  5466.       for (insn = get_last_insn (); len && insn; insn = PREV_INSN (insn))
  5467.         {
  5468.           if (GET_CODE (insn) == NOTE)
  5469.         {
  5470.           if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EPILOGUE_BEG)
  5471.             note = insn;
  5472.         }
  5473.           else if ((len -= contains (insn, epilogue)) == 0)
  5474.         {
  5475.           /* Find the epilogue-begin note if we haven't already, and
  5476.              move it to just before the first epilogue insn.  */
  5477.           if (note == 0)
  5478.             {
  5479.               for (note = insn; note = PREV_INSN (note);)
  5480.             if (GET_CODE (note) == NOTE
  5481.                 && NOTE_LINE_NUMBER (note) == NOTE_INSN_EPILOGUE_BEG)
  5482.               break;
  5483.             }
  5484.           next = NEXT_INSN (note);
  5485.           prev = PREV_INSN (note);
  5486.           if (prev)
  5487.             NEXT_INSN (prev) = next;
  5488.           if (next)
  5489.             PREV_INSN (next) = prev;
  5490.           add_insn_after (note, PREV_INSN (insn));
  5491.         }
  5492.         }
  5493.     }
  5494.     }
  5495. #endif /* HAVE_prologue or HAVE_epilogue */
  5496. }
  5497.